Contents of /trunk/mkinitrd-magellan/klibc/usr/kinit/getintfile.c
Parent Directory | Revision Log
Revision 815 -
(show annotations)
(download)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 493 byte(s)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 493 byte(s)
-updated to klibc-1.5.15
1 | /* |
2 | * Open a file and read it, assuming it contains a single long value. |
3 | * Return 0 if we read a valid value, otherwise -1. |
4 | */ |
5 | |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | |
9 | #include "kinit.h" |
10 | |
11 | int getintfile(const char *path, long *val) |
12 | { |
13 | char buffer[64]; |
14 | char *ep; |
15 | FILE *f; |
16 | |
17 | f = fopen(path, "r"); |
18 | if (!f) |
19 | return -1; |
20 | |
21 | ep = buffer + fread(buffer, 1, sizeof buffer - 1, f); |
22 | fclose(f); |
23 | *ep = '\0'; |
24 | |
25 | *val = strtol(buffer, &ep, 0); |
26 | if (*ep && *ep != '\n') |
27 | return -1; |
28 | else |
29 | return 0; |
30 | } |