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:
Bananymous 2023-09-07 15:47:59 +03:00
parent 7c11ea3694
commit 14ac1c9904
1 changed files with 4 additions and 8 deletions

View File

@ -35,15 +35,11 @@ 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");
{ return 1;
fprintf(stderr, "Could not read from stdin\n");
return 1;
}
continue;
} }
if (nread <= 1 || name_buffer[nread - 1] != '\n') if (nread <= 1 || name_buffer[nread - 1] != '\n')
continue; continue;