porting/dpl_os/src/config_file.c
/*
 * Called to load configuration items. cb must be called for every configuration
 * item found.
 */
Called to load configuration items. cb must be called for every configuration
item found.
Called to load configuration items . cb must be called for every configuration item found .
static int
conf_file_load(struct conf_store *cs, conf_store_load_cb cb, void *cb_arg)
{
    struct conf_file *cf = (struct conf_file *)cs;
    FILE *file;
    uint32_t loc;
    char tmpbuf[CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32];
    char *name_str;
    char *val_str;
    int rc;
    int lines;
    file = fopen(cf->cf_name, "r");
    if (!file) {
        return EINVAL;
    }
    loc = 0;
    lines = 0;
    while (1) {
        rc = conf_getnext_line(file, tmpbuf, sizeof(tmpbuf), &loc);
        if (loc == 0) {
            break;
        }
        if (rc < 0) {
            continue;
        }
        rc = conf_line_parse(tmpbuf, &name_str, &val_str);
        if (rc != 0) {
            continue;
        }
        lines++;
        cb(name_str, val_str, cb_arg);
    }
    fclose(file);
    cf->cf_lines = lines;
    return 0;
}
static int conf_file_load ( struct conf_store * cs , conf_store_load_cb cb , void * cb_arg ) { struct conf_file * cf = ( struct conf_file * ) cs ; FILE * file ; uint32_t loc ; char tmpbuf [ CONF_MAX_NAME_LEN + CONF_MAX_VAL_LEN + 32 ] ; char * name_str ; char * val_str ; int rc ; int lines ; file = fopen ( cf -> cf_name , " " ) ; if ( ! file ) { return EINVAL ; } loc = 0 ; lines = 0 ; while ( 1 ) { rc = conf_getnext_line ( file , tmpbuf , sizeof ( tmpbuf ) , & loc ) ; if ( loc == 0 ) { break ; } if ( rc < 0 ) { continue ; } rc = conf_line_parse ( tmpbuf , & name_str , & val_str ) ; if ( rc != 0 ) { continue ; } lines ++ ; cb ( name_str , val_str , cb_arg ) ; } fclose ( file ) ; cf -> cf_lines = lines ; return 0 ; }
Called to load configuration items.
Called to load configuration items .