src/util.c
/*
* Read configuration file
* TODO: trim input line
*/
Read configuration file
TODO: trim input line
Read configuration file TODO : trim input line
int read_conf(char *filename, zv_conf_t *cf, char *buf, int len) {
    FILE *fp = fopen(filename, "r");
    if (!fp) {
        log_err("cannot open config file: %s", filename);
        return ZV_CONF_ERROR;
    }
    int pos = 0;
    char *delim_pos;
    int line_len;
    char *cur_pos = buf+pos;
    while (fgets(cur_pos, len-pos, fp)) {
        delim_pos = strstr(cur_pos, DELIM);
        line_len = strlen(cur_pos);
        if (!delim_pos)
            return ZV_CONF_ERROR;
        if (cur_pos[strlen(cur_pos) - 1] == '\n') {
            cur_pos[strlen(cur_pos) - 1] = '\0';
        }
        if (strncmp("root", cur_pos, 4) == 0) {
            cf->root = delim_pos + 1;
        }
        if (strncmp("port", cur_pos, 4) == 0) {
            cf->port = atoi(delim_pos + 1);     
        }
        if (strncmp("threadnum", cur_pos, 9) == 0) {
            cf->thread_num = atoi(delim_pos + 1);
        }
        cur_pos += line_len;
    }
    fclose(fp);
    return ZV_CONF_OK;
}
int read_conf ( char * filename , zv_conf_t * cf , char * buf , int len ) { FILE * fp = fopen ( filename , " " ) ; if ( ! fp ) { log_err ( " " , filename ) ; return ZV_CONF_ERROR ; } int pos = 0 ; char * delim_pos ; int line_len ; char * cur_pos = buf + pos ; while ( fgets ( cur_pos , len - pos , fp ) ) { delim_pos = strstr ( cur_pos , DELIM ) ; line_len = strlen ( cur_pos ) ; if ( ! delim_pos ) return ZV_CONF_ERROR ; if ( cur_pos [ strlen ( cur_pos ) - 1 ] == ' \n ' ) { cur_pos [ strlen ( cur_pos ) - 1 ] = ' \0 ' ; } if ( strncmp ( " " , cur_pos , 4 ) == 0 ) { cf -> root = delim_pos + 1 ; } if ( strncmp ( " " , cur_pos , 4 ) == 0 ) { cf -> port = atoi ( delim_pos + 1 ) ; } if ( strncmp ( " " , cur_pos , 9 ) == 0 ) { cf -> thread_num = atoi ( delim_pos + 1 ) ; } cur_pos += line_len ; } fclose ( fp ) ; return ZV_CONF_OK ; }
Read configuration file
TODO: trim input line
Read configuration file TODO : trim input line
/*
        debug("read one line from conf: %s, len = %d", cur_pos, line_len);
        */