PMFSTRING(3)
π NAME π
okay bestie, listen up β pmfstring is your girl for safe string scanning. that's literally it, that's the whole vibe. β¨
πΈ C SYNOPSIS πΈ
like, here's how you actually use her:
#include <pcp/pmapi.h>
ssize_t pmfstring(FILE *f, char **str);
and when you compile, don't forget:
cc ... -lpcp
π DESCRIPTION π
so pmfstring is a safe string scanning routine β she does basically the same thing as fscanf(3) with the %s format specifier, but make it responsible. π
here's the tea on what she does: she scans the input stream from f, skips over all the initial whitespace characters, and then just... accumulates every subsequent non-whitespace character. like a little vacuum but for chars. π§Ή
the main difference (and this is the important part, no cap) is that pmfstring allocates the result buffer str using the malloc(3) family β and she makes sure that str is:
- (a) large enough, and
- (b) null-byte terminated
so you literally never have to worry about that yourself. she handles it. icon behaviour, honestly. π
on top of all that, pmfstring does not consider \n to be a whitespace character in that initial scan (the one before filling str). so she will not scan past the end of the current line. this is different from fscanf(3) and β good news β way better aligned with the PCP use cases. fr fr. π¦
bestie, heads up: you are responsible for maintaining a reference to str, or calling free(3) to release the associated storage. don't be the person who leaks. we don't know her. π«Ά
on success, pmfstring returns the length of str β same length strlen(3) would return β and it's guaranteed to be not less than 1. periodt.
if it fails, you get one of these, and str is not assigned a value:
0β meaning no non-whitespace characters were found before the end of the current line from the stream f-1(akaEOF) β meaning end of file on the stream f-2β meaning some more serious failure, probably in themalloc(3)routines; refer toerrnofor more information π
π COMPATIBILITY π
pmfstring has similar semantics to the %ms format specifier in some versions of fscanf(3), and to the C99 fscanf_s(3) routine. and the tragic part? unfortunately neither of these is portable. π so yeah. that's why she exists.
β SEE ALSO β
free(3), fscanf(3), malloc(3) and strlen(3).
k bye, this page came to you straight from Performance Co-Pilot (PCP) β the PMFSTRING(3) girlies know π β mwah, go free your strings πβ¨
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2021 Ken McDonell
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms