OPENPAM_READLINEV(3)

πŸ“¦
version 14.5 Β· 2 versions
, in freebsd 14.5, nixos 26.05, nixpkgs unstable

πŸ’… 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; errno is zero, ferror(3) returns zero, and feof(3) returns a non-zero value.
  • The end of the file was reached while a quote or backslash escape was in effect; errno is set to EINVAL, ferror(3) returns zero, and feof(3) returns a non-zero value.
  • An error occurred while reading from the file; errno is non-zero, ferror(3) returns a non-zero value and feof(3) returns zero.
  • A malloc(3) or realloc(3) call failed; errno is set to ENOMEM, ferror(3) returns a non-zero value, and feof(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