Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/fgets.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 421 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 421 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* |
2 | * fgets.c |
3 | * |
4 | * This will be very slow due to the implementation of getc(), |
5 | * but we don't have anywhere to put characters we don't need from |
6 | * the input. |
7 | */ |
8 | |
9 | #include <stdio.h> |
10 | |
11 | char *fgets(char *s, int n, FILE *f) |
12 | { |
13 | int ch; |
14 | char *p = s; |
15 | |
16 | while (n > 1) { |
17 | ch = getc(f); |
18 | if (ch == EOF) { |
19 | *p = '\0'; |
20 | return NULL; |
21 | } |
22 | *p++ = ch; |
23 | n--; |
24 | if (ch == '\n') |
25 | break; |
26 | } |
27 | if (n) |
28 | *p = '\0'; |
29 | |
30 | return s; |
31 | } |