PMFSTRING(3) | Library Functions Manual | PMFSTRING(3) |
pmfstring - safe string scanning
#include <pcp/pmapi.h>
ssize_t pmfstring(FILE *f, char **str);
cc ... -lpcp
pmfstring is a safe string scanning routine with semantics similar to fscanf(3) with the %s format specifier. It scans the input stream from f skipping initial whitespace characters, then accumulating all the subsequent non-whitespace characters.
The main difference is that pmfstring allocates the result buffer str using the malloc(3) family and ensures that str is (a) large enough and (b) null-byte terminated.
Additionally pmfstring does not consider \n to be a whitespace character in the initial scan (before filling str) and so will not scan past the end of the current line, which is different to fscanf(3) and better aligned with the PCP use cases.
The caller is responsible for maintaining a reference to str or calling free(3) to release the associated storage.
On success, pmfstring returns the length of str (the same length as strlen(3) would return) that is guaranteed to be not less than 1.
Failure is indicated by one of the following, and str is not assigned a value:
pmfstring has similar semantics to the %ms format specifier in some versions of fscanf(3) and the C99 fscanf_s(3) routine - unfortunately neither of these is portable.
PCP | Performance Co-Pilot |