Contents of /trunk/mkinitrd-magellan/klibc/usr/kinit/getintfile.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: 473 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 473 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 | * 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 | int getintfile(const char *path, long *val) |
10 | { |
11 | char buffer[64]; |
12 | char *ep; |
13 | FILE *f; |
14 | |
15 | f = fopen(path, "r"); |
16 | if (!f) |
17 | return -1; |
18 | |
19 | ep = buffer + fread(buffer, 1, sizeof buffer - 1, f); |
20 | fclose(f); |
21 | *ep = '\0'; |
22 | |
23 | *val = strtol(buffer, &ep, 0); |
24 | if (*ep && *ep != '\n') |
25 | return -1; |
26 | else |
27 | return 0; |
28 | } |