"Fossies" - the Fresh Open Source Software archive

Member "open-fcoe/usr/common/libsa/src/sa_sys_read_u32.c" of archive open-fcoe.tar.gz:


/*
 * Copyright(c) 2007 Intel Corporation. All rights reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Maintained at www.Open-FCoE.org
 */
#include <sys/types.h>
#include <stdlib.h>

#include "sa_sys.h"
#include "sa_log.h"


int
sa_sys_read_u32(const char *dir, const char *file, u_int32_t *vp)
{
    char buf[256];
    int rc;
    u_int32_t val;
    char *endptr;

    rc = sa_sys_read_line(dir, file, buf, sizeof (buf));
    if (rc == 0) {
        val = strtoul(buf, &endptr, 0);
        if (*endptr != '\0') {
            SA_LOG("parse error. file %s/%s line '%s'", dir, file, buf);
            rc = -1;
        } else {
            *vp = val;
        }
    }
    return (rc);
}