/*
* Writestring uses the writen and strlen calls to write a
* string to the file descriptor fd. If the write fails
* a -1 is returned. Otherwise zero is returned.
*/
int
writestring(fd, stringptr)
int fd;
char *stringptr;
{
int length;
/*
* Read a line from a descriptor. Read the line one byte at a time,
* looking for the newline. We store the newline in the buffer,
* then follow it with a null (the same as fgets(3)).
* We return the number of characters up to, but not including,
* the null (the same as strlen(3))
*/
int
readline(fd, ptr, maxlen)
int fd;
char *ptr;
int maxlen;
{
int n;
int rc;
char c;
for (n=1; n < maxlen; n++) {
#ifdef MULTINET
if ( (rc = socket_read(fd, &c, 1)) == 1) {
#endif
#ifdef WOLLONGONG
if ( (rc = netread(fd, &c, 1)) == 1) {
#endif
#ifdef UCX
if ( (rc = read(fd, &c, 1)) == 1) {
#endif
*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; /* Tack a NULL on the end */
return(n);
}
/*
* ZapCRLF removes all carriage returns and linefeeds from a C-string.
*/