- while( fgets( filebuffer, BUFSIZE, fh)!= NULL){
- /*skip first line and split file on : */
- if (count != 0){
- position = strchr(filebuffer,':');
- start = strlen(filebuffer) - 1;
- filebuffer[start] = '\0';
- /* : is located at value 8, +1 to remove space */
- strncpy(valuebuffer, ptrfilebuffer+9, start);
- /*store section info for later */
- strncpy(sectionbuffer, ptrfilebuffer, position - filebuffer);
- position = strchr(sectionbuffer, ' ');
- if (position != NULL){
- sectionbuffer[position-sectionbuffer] = '\0';
- }
-
- /*split rest of line by space and then split that via =*/
- numfields = strsplit ( valuebuffer, fields,
- fscache_number_of_values);
- for( forcount = 0; forcount < numfields; forcount++ ){
- char *field = fields[forcount];
- memset(valuename,'\0',sizeof(valuename));
- position = strchr(field, '=');
- /* Test to see if we actually have a metric to split on
- * and assign the values to the struct array */
- if (position != NULL){
- strncpy(valuename, field, position - field);
- strncpy(valuevalue, field + (position - field + 1),
- strlen(field));
- memset(tempstring,'\0',sizeof(tempstring));
- strncat(tempstring,sectionbuffer,sizeof(tempstring));
- strncat(tempstring,"_",1);
- strncat(tempstring,valuename, sizeof(tempstring));
- memset(values[valuecounter].name,'\0',
- sizeof(values[valuecounter].name));
- strncpy(values[valuecounter].name,tempstring,
- sizeof(values[valuecounter].name));
- values[valuecounter].value = atoll(valuevalue);
- }
- valuecounter++;
- }
+ while (fgets (linebuffer, sizeof (linebuffer), fh) != NULL)
+ {
+ char *lineptr;
+ char *fields[32];
+ int fields_num;
+ int i;
+
+ /* Find the colon and replace it with a null byte */
+ lineptr = strchr (linebuffer, ':');
+ if (lineptr == NULL)
+ continue;
+ *lineptr = 0;
+ lineptr++;
+
+ /* Copy and clean up the section name */
+ sstrncpy (section, linebuffer, sizeof (section));
+ section_len = strlen (section);
+ while ((section_len > 0) && isspace ((int) section[section_len - 1]))
+ {
+ section_len--;
+ section[section_len] = 0;