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;
|
||||
unsigned int i;
|
||||
for (i=0;
|
||||
(i < len) && ((res = read(fd, &c, 1)) != 0)
|
||||
(i < (len-1)) && ((res = read(fd, &c, 1)) != 0)
|
||||
&& ((c != '\n') && (c != '\r'));
|
||||
i++)
|
||||
buf[i] = c;
|
||||
|
@ -72,6 +72,8 @@ int reads(int fd, char *buf, unsigned int len) {
|
|||
if (buf[i] == '\r')
|
||||
buf[i] = '\n';
|
||||
|
||||
buf[++i] = '\0';
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue