From f1e764a7e78da0f8f6997e47d6e0807056cfc8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 3 May 2004 12:28:48 +0000 Subject: [PATCH] No longer uses fgetln() - that call is not part of the POSIX specs, and is not supported by the GLIBC stdio that we now have. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7369 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/apps/tests/fops_test.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/kernel/apps/tests/fops_test.c b/src/kernel/apps/tests/fops_test.c index 5a4818afaf..0036a57783 100644 --- a/src/kernel/apps/tests/fops_test.c +++ b/src/kernel/apps/tests/fops_test.c @@ -14,26 +14,28 @@ #define NEW_FORTUNE "The path has been shown - we are the ones who must walk it" -static void read_file(FILE *f) +static void +read_file(FILE *f) { + char buffer[2048]; int lines = 0; - char *buffer, *tmp; - size_t bytes = 0; - - while ((buffer = fgetln(f, &bytes)) != NULL) { - if (*buffer == '#') + + while ((fgets(buffer, sizeof(buffer), f)) != NULL) { + size_t bytes = strlen(buffer); + + if (buffer[0] == '#') continue; - tmp = (char*) malloc(bytes + 1); - if (!tmp) - break; - memcpy(tmp, buffer, bytes); - if (tmp[bytes - 1] != '\n') - tmp[bytes - 1] = '\n'; - fprintf(stdout, "%d: %s", ++lines, tmp); + + if (buffer[bytes - 1] != '\n') + buffer[bytes - 1] = '\n'; + + fprintf(stdout, "%d: %s", ++lines, buffer); } } -int main(int argc, char **argv) + +int +main(int argc, char **argv) { FILE *f;