Don't forget to terminate the string
This commit is contained in:
parent
da7d172d37
commit
0599f873dc
1 changed files with 3 additions and 1 deletions
|
@ -64,7 +64,7 @@ int reads(int fd, char *buf, unsigned int len) {
|
||||||
int res;
|
int res;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
for (i=0;
|
for (i=0;
|
||||||
(i < len) && ((res = read(fd, &c, 1)) != 0)
|
(i < (len-1)) && ((res = read(fd, &c, 1)) != 0)
|
||||||
&& ((c != '\n') && (c != '\r'));
|
&& ((c != '\n') && (c != '\r'));
|
||||||
i++)
|
i++)
|
||||||
buf[i] = c;
|
buf[i] = c;
|
||||||
|
@ -72,6 +72,8 @@ int reads(int fd, char *buf, unsigned int len) {
|
||||||
if (buf[i] == '\r')
|
if (buf[i] == '\r')
|
||||||
buf[i] = '\n';
|
buf[i] = '\n';
|
||||||
|
|
||||||
|
buf[++i] = '\0';
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue