@@ -10,41 +10,52 @@ #ifdef HAVE_STRING_H #include #endif int lc_process_conf_section(const char *appname, const char *configfile) { - FILE *configfp = NULL; + LC_FILE *configfp = NULL; + const char *local_lc_errfile; char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL; char qualifbuf[LC_LINEBUF_LEN] = {0}; char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL; char *currsection = NULL; char *fgetsret = NULL; int lcpvret = -1; int invalid_section = 1, ignore_section = 0; + int local_lc_errline; int retval = 0; lc_err_t save_lc_errno = LC_ERR_NONE; + + local_lc_errfile = configfile; + local_lc_errline = 0; if (appname == NULL || configfile == NULL) { + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_INVDATA; return(-1); } configfp = lc_fopen(configfile, "r"); if (configfp == NULL) { + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_CANTOPEN; return(-1); } while (1) { - fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp); + fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp); if (fgetsret == NULL) { break; } - if (feof(configfp)) { + if (lc_feof(configfp)) { break; } + + local_lc_errline++; /* Remove trailing crap (but not spaces). */ linebuf_ptr = &linebuf[strlen(linebuf) - 1]; while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) { *linebuf_ptr = '\0'; @@ -73,10 +84,12 @@ if (lcpvret < 0) { #ifdef DEBUG fprintf(stderr, "Invalid section: \"%s\"\n", currsection); #endif invalid_section = 1; + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; lc_errno = LC_ERR_INVSECTION; retval = -1; } else { invalid_section = 0; ignore_section = 0; @@ -161,10 +174,12 @@ } else { #ifdef DEBUG fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n"); #endif } + lc_errfile = local_lc_errfile; + lc_errline = local_lc_errline; retval = -1; } else { lc_errno = save_lc_errno; } } @@ -178,9 +193,9 @@ #endif } free(currsection); } - fclose(configfp); + lc_fclose(configfp); return(retval); }