linux - Is there a widespread C library for reading name/value pairs from a file? -


My program is reading a text file that has different rows of text for the settings file. Some lines may be too large, buffer size is currently 4096 characters. It is possible that some lines may be higher than this, whether malicious or due to various factors working within the program.

The current routine was difficult to write and now I want to extend the possible contents of the file for which this tedious repetitive code will be required more. (This is for a settings type file, which includes name value and sometimes section headers. Many exact values ​​need to be read in the form of string because of many precision).

The main thing I want to do is read an arbitrary length line without a buffer overflow. I have just come to know what this can do for me, but there is a library for heaven, which is just for this exhaustion Will work perfectly?

Edit:

I do not want to be forced to put a = mark between names and values, a blank The location should be sufficient as a separator

Widely, I mean that the library should be available in the standard Linux distribution package.

I know but it takes full overkill for my needs.

I suggest, DIY, because it is quite easy.

  • Read each row
  • Count
  • Allocation buffer
  • and sscanf

    To read name value pairs:

    sscanf (line, "% [^:]:% [^ \ n]", key, value);

  • You will be safe as you count the characters before sccanf .


    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -