1
0
Fork 0

Make reads() more robust and easier to follow

This commit is contained in:
ehofman 2003-08-28 12:36:31 +00:00
parent 0599f873dc
commit 703fc67636

View file

@ -60,19 +60,21 @@ double round( double a ) {
int reads(int fd, char *buf, unsigned int len) { int reads(int fd, char *buf, unsigned int len) {
char c; unsigned int i = 0;
int res; int res;
unsigned int i; char c;
for (i=0;
(i < (len-1)) && ((res = read(fd, &c, 1)) != 0)
&& ((c != '\n') && (c != '\r'));
i++)
buf[i] = c;
if (buf[i] == '\r') len--;
buf[i] = '\n'; while ( (i < len) && ((res = read(fd, &c, 1)) != 0)
&& ((c != '\n') && (c != '\r')) )
{
buf[i++] = c;
}
buf[++i] = '\0'; if ((c == '\r') || (c == '\n'))
buf[i++] = '\n';
buf[i] = '\0';
return res; return res;
} }