summaryrefslogtreecommitdiff
path: root/head.c
diff options
context:
space:
mode:
Diffstat (limited to 'head.c')
-rw-r--r--head.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/head.c b/head.c
index 1642186..58ee02a 100644
--- a/head.c
+++ b/head.c
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-#define _XOPEN_SOURCE 700
+#define _POSIX_C_SOURCE 2
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -41,13 +41,12 @@ static int head(const char *path, int nlines)
return 1;
}
- while (!feof(f) && nlines > 0) {
- char *line = NULL;
- size_t n = 0;
-
- getline(&line, &n, f);
- fputs(line, stdout);
- nlines--;
+ int c;
+ while ((c = fgetc(f)) != EOF && nlines > 0) {
+ putchar(c);
+ if (c == '\n') {
+ nlines--;
+ }
}
if (f != stdin) {