~ubuntu-branches/ubuntu/hardy/klibc/hardy-updates

« back to all changes in this revision

Viewing changes to usr/kinit/getintfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2006-01-04 20:24:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104202452-ec4v3n829rymukuv
Tags: 1.1.15-0ubuntu1
* New upstream version.

* Patch to fix compilation on parisc64 kernels.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * getintfile.c
 
3
 *
 
4
 * Open a file and read it, assuming it contains a single long value.
 
5
 * Return 0 if we read a valid value, otherwise -1.
 
6
 */
 
7
 
 
8
#include <stdio.h>
 
9
#include <stdlib.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
}
 
31
 
 
32
 
 
33