You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
echoping/SRC/readline.c

46 lines
724 B
C

24 years ago
/*
* Read a line from a descriptor with fgets
*
* $Id$
*
*/
24 years ago
#include "echoping.h"
int
readline (fs, ptr, maxlen, ln)
FILE *fs;
24 years ago
char *ptr;
int maxlen;
unsigned short ln;
{
int n = 1;
char *rc;
if (ln) {
rc = fgets (ptr, maxlen+1, fs);
/* printf ("DEBUG: %d bytes asked, I read \"%s\"\n", maxlen, rc); */
if (rc == NULL) {
return (-1);
24 years ago
}
n = strlen (rc);
return n;
}
else {
while (n < maxlen) {
rc = fgets (ptr, maxlen, fs);
if (rc == NULL) {
if (timeout_flag)
return n;
if (n == 1)
return (0); /* EOF, no data read */
else
break; /* EOF, some data was read */
}
n = n + strlen (rc);
}
}
24 years ago
return (n);
}