1
2PMFSTRING(3) Library Functions Manual PMFSTRING(3)
3
4
5
7 pmfstring - safe string scanning
8
10 #include <pcp/pmapi.h>
11
12 ssize_t pmfstring(FILE *f, char **str);
13
14 cc ... -lpcp
15
17 pmfstring is a safe string scanning routine with semantics similar to
18 fscanf(3) with the %s format specifier. It scans the input stream from
19 f skipping initial whitespace characters, then accumulating all the
20 subsequent non-whitespace characters.
21
22 The main difference is that pmfstring allocates the result buffer str
23 using the malloc(3) family and ensures that str is (a) large enough and
24 (b) null-byte terminated.
25
26 Additionally pmfstring does not consider \n to be a whitespace charac‐
27 ter in the initial scan (before filling str) and so will not scan past
28 the end of the current line, which is different to fscanf(3) and better
29 aligned with the PCP use cases.
30
31 The caller is responsible for maintaining a reference to str or calling
32 free(3) to release the associated storage.
33
34 On success, pmfstring returns the length of str (the same length as
35 strlen(3) would return) that is guaranteed to be not less than 1.
36
37 Failure is indicated by one of the following, and str is not assigned a
38 value:
39 • 0 to indicate no non-whitespace characters were found before the end
40 of the current line from the stream f
41 • -1 ( aka EOF) to indicate end of file on the stream f
42 • -2 to indicate some more serious failure, probably in the malloc(3)
43 routines; refer to errno for more information
44
46 pmfstring has similar semantics to the %ms format specifier in some
47 versions of fscanf(3) and the C99 fscanf_s(3) routine - unfortunately
48 neither of these is portable.
49
51 free(3), fscanf(3), malloc(3) and strlen(3).
52
53
54
55Performance Co-Pilot PCP PMFSTRING(3)