#include /* standard C i/o facilities */ #include /* readline - from the Stevens book (Unix Network Programming) */ int readline(int fd, void *vptr, int maxlen) { int n, rc; char c, *ptr; ptr = vptr; for (n = 1; n < maxlen; n++) { if ( (rc = read(fd, &c, 1)) == 1) { *ptr++ = c; if (c == '\n') break; } else if (rc == 0) { if (n == 1) return(0); /* EOF, no data read */ else break; /* EOF, some data was read */ } else return(-1); /* error */ } *ptr = 0; return(n); } /* end readline */ int writeline( int fd, char *s ) { int res; res = write(fd,s,strlen(s)); if (res!=strlen(s)) return(-1); if (2!=write(fd,"\r\n",2)) return(-1); return(res+2); }