forked from Bananymous/banan-os
Init: use read instead of fread()
This allows actually correct behaviour. My fread implementation is flawed. It should not return on '\n'
This commit is contained in:
parent
7c11ea3694
commit
14ac1c9904
|
@ -35,16 +35,12 @@ int main()
|
||||||
printf("username: ");
|
printf("username: ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
size_t nread = fread(name_buffer, 1, sizeof(name_buffer) - 1, stdin);
|
ssize_t nread = read(STDIN_FILENO, name_buffer, sizeof(name_buffer) - 1);
|
||||||
if (nread == 0)
|
if (nread == -1)
|
||||||
{
|
{
|
||||||
if (ferror(stdin))
|
perror("read");
|
||||||
{
|
|
||||||
fprintf(stderr, "Could not read from stdin\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (nread <= 1 || name_buffer[nread - 1] != '\n')
|
if (nread <= 1 || name_buffer[nread - 1] != '\n')
|
||||||
continue;
|
continue;
|
||||||
name_buffer[nread - 1] = '\0';
|
name_buffer[nread - 1] = '\0';
|
||||||
|
|
Loading…
Reference in New Issue