return;
}
-/****************************************************/
-/* Read one line */
-/* fd: file descriptor */
-/* vptr: input buffer pointer */
-/* maxlen: buffer length */
-/* return value is the count of readin chars */
-/* if error, return -1 */
-/* ## this function assumes two EOL chars [CR LF] */
-/****************************************************/
+
+/******************************************************/
+/* Read one line */
+/* fd: file descriptor */
+/* vptr: input buffer pointer */
+/* maxlen: buffer length */
+/* */
+/* the chars terminated with EOL or EOF is read in */
+/* ## this function assumes two EOL chars [CR LF] */
+/* CRLF is not read in and skipped */
+/* [abcdCRLFefghCRLF] => read[abcd],left[efghCRLF] */
+/* */
+/* return value */
+/* plus value means the count of chars to read */
+/* value 0 means NULL line (no-chars & CRLF) */
+/* value -1 means error (errno is set) */
+/* value -2 means EOF (no-chars & EOF) */
+/******************************************************/
ssize_t
readln(int fd, void *vptr, size_t maxlen)
{
/* pre read */
rc = read(fd, &c, 1);
- if(rc<=0) return(-1);
+ if(rc==0) return(-2); /* EOF */
+ if(rc<0) return(-1); /* ERR */
/* get char loop */
n=0;
}
*ptr++ = c;
n++;
- }else if (rc == 0) { /* EOF */
+ }else if (rc == 0) { /* EOF (but some chars are read already) */
break;
} else { /* ERR */
return(-1);
return(n);
}
+
ssize_t
readlnSSL(SSL *fd, void *vptr, size_t maxlen)
{
/* pre read */
rc = SSL_read(fd, &c, 1);
- if(rc<=0) return(-1);
+ if(rc==0) return(-2); /* EOF */
+ if(rc<0) return(-1); /* ERR */
/* get char loop */
n=0;
}
*ptr++ = c;
n++;
- }else if (rc == 0) { /* EOF */
+ }else if (rc == 0) { /* EOF (but some char are read already */
break;
} else { /* ERR */
return(-1);
return(n);
}
+
/******************************/
/* lock functions using fcntl */
/******************************/