/* 4m v2.15 (readpacket.c)
 * (C) Copyright 1990 by Carrick Sean Casey
 * (C) Copyright 1993 by Scott Chasin and Michaeljon Miller
 *
 * 3-22-93 See file COPYING for copyright information.
 *
 * Packet importing
 *
 */

#include <stdio.h>
#include <sys/types.h>
#include <errno.h>

#ifdef NEEDS_SELECT
# include "select.h"
#endif

#include "ipcf.h"
#include "externs.h"

extern int errno;


extern int read ();

int _readpacket(s, buf)
     int s;
     char *buf;
{
    int to = 0, ret;
    char c;

    do {
        if ((ret = read(s, &c, 1)) < 0)
            if (errno == EWOULDBLOCK)
                return (0);
            else
                return (-1);

        if (!ret)
            return (-2);

        if ((c >= ' ') || (c <= 126))
            if (to < 1024 - 1)
                buf[to++] = c;
    } while (c != '\n');

    buf[to] = '\0';

    return (1);
}
