FNPATHFIND(3pub)

✨ FNPATHFIND(3pub) ✨

okay bestie, welcome to the C Programmer's Manual, section 3pub πŸ’– this one's a little publib baddie called fnpathfind, and she is literally the friend who knows where everything is.


🌸 NAME 🌸

fnpathfind β€” find a file in a list of directories πŸ¦‹


✨ SYNOPSIS ✨

#include <publib.h>

int fnpathfind(const char *path, const char *tgt,
                     char *res, size_t max);

πŸ’… DESCRIPTION πŸ’…

so pathfind (that's our girl, also known as fnpathfind, iykyk) goes looking for a file inside a whole list of directories. the path argument is a colon separated list of directories β€” and it's typically the contents of an environment variable like PATH, MANPATH, or CDPATH. iconic behaviour honestly 🫢

what she does: she walks through the directories in the path, one by one, and in each directory she looks for the file given in the argument target, and she keeps going until she finds it. that's it, that's the whole vibe check. only an exact match gets reported β€” no wild cards, no globbing, none of that βœ‹

the names she matches are formed by taking an element from the path and prepending it to target. and listen, this part matters: an empty element means the current directory, and the name "." means the current directory too πŸ‘‘

return value tea β˜•: the function returns -1 for failure (either not found, or an error), or otherwise the total size of the full name. and heads up β€” the full name may have been truncated when it got stored into result. not her fault, she's just reporting the size okay 😭


πŸ’€ BUGS πŸ’€

  • she uses dynamic memory allocation, so she may fail due to insufficient memory. memory said no and now everyone's sad πŸ™ˆ
  • it is not trivial to know in which directory the search ended. this makes it difficult to continue the search. so if you were hoping to pick up where she left off... good luck bestie πŸ’€

πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ AUTHOR πŸ‘‘

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” thank you for your service king 🫑


and that's a wrap on this page from the Publib era of the C Programmer's Manual (section 3pub) πŸŽ€ no date on the original footer, just vibes and version energy, so that's your cute lil sign-off fr fr βœ¨πŸ’œ

πŸ“¦ where this page comes from