From 14ac1c9904eb3558e193c33ca7be39c3217a03e4 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 7 Sep 2023 15:47:59 +0300 Subject: [PATCH] Init: use read instead of fread() This allows actually correct behaviour. My fread implementation is flawed. It should not return on '\n' --- userspace/init/main.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/userspace/init/main.cpp b/userspace/init/main.cpp index 1337cd42c8..540d4d7da9 100644 --- a/userspace/init/main.cpp +++ b/userspace/init/main.cpp @@ -35,15 +35,11 @@ int main() printf("username: "); fflush(stdout); - size_t nread = fread(name_buffer, 1, sizeof(name_buffer) - 1, stdin); - if (nread == 0) + ssize_t nread = read(STDIN_FILENO, name_buffer, sizeof(name_buffer) - 1); + if (nread == -1) { - if (ferror(stdin)) - { - fprintf(stderr, "Could not read from stdin\n"); - return 1; - } - continue; + perror("read"); + return 1; } if (nread <= 1 || name_buffer[nread - 1] != '\n') continue;