X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fprocfile.h;h=98765697f59ea07dc735a4e6e7a1bdf44a31705c;hb=909e26f825bc1f6f907231761412c885331fec7e;hp=b360f4441972ab1b00d572e4a176c2ba25238174;hpb=e8b3c968037dff4a35de75272998333ac382e51d;p=netdata.git diff --git a/src/procfile.h b/src/procfile.h old mode 100755 new mode 100644 index b360f444..98765697 --- a/src/procfile.h +++ b/src/procfile.h @@ -1,6 +1,6 @@ /* * procfile is a library for reading kernel files from /proc - * + * * The idea is this: * * - every file is opened once with procfile_open(). @@ -30,9 +30,9 @@ // An array of words typedef struct { - uint32_t len; // used entries - uint32_t size; // capacity - char *words[]; // array of pointers + size_t len; // used entries + size_t size; // capacity + char *words[]; // array of pointers } pfwords; @@ -40,30 +40,44 @@ typedef struct { // An array of lines typedef struct { - uint32_t words; // how many words this line has - uint32_t first; // the id of the first word of this line - // in the words array + size_t words; // how many words this line has + size_t first; // the id of the first word of this line + // in the words array } ffline; typedef struct { - uint32_t len; // used entries - uint32_t size; // capacity - ffline lines[]; // array of lines + size_t len; // used entries + size_t size; // capacity + ffline lines[]; // array of lines } pflines; // ---------------------------------------------------------------------------- // The procfile +#define PROCFILE_FLAG_DEFAULT 0x00000000 +#define PROCFILE_FLAG_NO_ERROR_ON_FILE_IO 0x00000001 + +typedef enum procfile_separator { + PF_CHAR_IS_SEPARATOR, + PF_CHAR_IS_NEWLINE, + PF_CHAR_IS_WORD, + PF_CHAR_IS_QUOTE, + PF_CHAR_IS_OPEN, + PF_CHAR_IS_CLOSE +} PF_CHAR_TYPE; + typedef struct { - char filename[FILENAME_MAX + 1]; - int fd; // the file desriptor - size_t len; // the bytes we have placed into data - size_t size; // the bytes we have allocated for data - pflines *lines; - pfwords *words; - char separators[256]; - char data[]; // allocated buffer to keep file contents + char filename[FILENAME_MAX + 1]; // not populated until profile_filename() is called + + uint32_t flags; + int fd; // the file desriptor + size_t len; // the bytes we have placed into data + size_t size; // the bytes we have allocated for data + pflines *lines; + pfwords *words; + PF_CHAR_TYPE separators[256]; + char data[]; // allocated buffer to keep file contents } procfile; // close the proc file and free all related memory @@ -73,15 +87,20 @@ extern void procfile_close(procfile *ff); extern procfile *procfile_readall(procfile *ff); // open a /proc or /sys file -extern procfile *procfile_open(const char *filename, const char *separators); +extern procfile *procfile_open(const char *filename, const char *separators, uint32_t flags); // re-open a file -// the separators argument is only used if ff == NULL -extern procfile *procfile_reopen(procfile *ff, const char *filename, const char *separators); +// if separators == NULL, the last separators are used +extern procfile *procfile_reopen(procfile *ff, const char *filename, const char *separators, uint32_t flags); // example walk-through a procfile parsed file extern void procfile_print(procfile *ff); +extern void procfile_set_quotes(procfile *ff, const char *quotes); +extern void procfile_set_open_close(procfile *ff, const char *open, const char *close); + +extern char *procfile_filename(procfile *ff); + // ---------------------------------------------------------------------------- // set this to 1, to have procfile adapt its initial buffer allocation to the max allocation used so far