OPENPAM_READLINEV(3)
π openpam_readlinev β bestie's guide to reading a line and splitting it into words π
Okay so this is OPENPAM_READLINEV(3), from the Library Functions Manual β and like, it's giving "small function, big personality." Let's get into it β¨
β¨ NAME β¨
openpam_readlinev β reads a line from a file and splits it into words, no cap π«Ά
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <stdio.h>
#include <security/pam_appl.h>
#include <security/openpam.h>
char **
openpam_readlinev(FILE *f, int *lineno, int *lenp);
Like, yes, that's four whole includes. She's thorough. We stan a prepared queen π
π DESCRIPTION π
So openpam_readlinev() does exactly what it says on the tin, bestie: it reads a line from a file, splits it into words following the rules laid out in the openpam_readword(3) manual page, and hands you back a list of those words. Iconic behavior, honestly.
If lineno is not NULL, the integer variable it points to gets incremented every single time a newline character is read β and yes, that includes quoted or escaped newline characters, plus the newline character at the end of the line. She counts all of them. Not me keeping track of every newline like that π
If lenp is not NULL, the number of words on the line gets stored in the variable it points to. Cute little word count, for free π
π₯ RETURN VALUES π₯
If everything goes well, openpam_readlinev() returns a pointer to a dynamically allocated array of pointers to individual dynamically allocated NUL-terminated strings, each one containing a single word, in the order they were encountered on the line. And the whole array is terminated by a NULL pointer, obviously β gotta know where it ends π
Real talk though: the caller is responsible for freeing both the array and the individual strings, by passing each of them to free(3). So like, don't ghost your mallocs. Free your stuff. Periodt π
If the end of the line was reached before any words were read, openpam_readlinev() returns a pointer to a dynamically allocated array containing a single NULL pointer. Tiny array, no words, still yours to free π
Now β the openpam_readlinev() function can fail and return NULL for one of four reasons:
- The end of the file was reached before any words were read;
errnois zero,ferror(3)returns zero, andfeof(3)returns a non-zero value. - The end of the file was reached while a quote or backslash escape was in effect;
errnois set toEINVAL,ferror(3)returns zero, andfeof(3)returns a non-zero value. - An error occurred while reading from the file;
errnois non-zero,ferror(3)returns a non-zero value andfeof(3)returns zero. - A
malloc(3)orrealloc(3)call failed;errnois set toENOMEM,ferror(3)returns a non-zero value, andfeof(3)may or may not return a non-zero value.
Four failure modes, four little vibes. Learn them, iykyk π
π¦ SEE ALSO π¦
Go read the friends, they're literally right there π«
β STANDARDS β
The openpam_readlinev() function is an OpenPAM extension. So like, she's not standard-standard, she's special β main character energy, honestly π
π§ AUTHORS π§
The openpam_readlinev() function and this manual page were developed by Dag-Erling SmΓΈrgrav <des@des.no>. We love a dual-threat icon π
That's the whole page, bestie β June 27, 2023, Debian edition, OPENPAM_READLINEV(3), wrapped up with a bow π Now go forth and read those lines, and remember: <kbd>Ctrl</kbd>+C is always there for you π«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- nixos 26.05: openpam 20230627
- nixpkgs unstable: openpam 20230627
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms