PATH(3)
β¨ PATH(3) β¨
omg bestie, welcome to the path page π this is from the Library Functions Manual and it's literally all about file path routines. no cap, it's a whole vibe. let's get into it π¦
NAME
path β file path routines β¨ (like, what it says on the tin, periodt)
SYNOPSIS
#include <ast.h>
char* pathaccess(char* path, const char* dirs, const char* a, const char* b, int mode);
char* pathbin(void);
char* pathcanon(char* path, int flags);
char* pathcat(char* path, const char* dirs, int sep, const char* a, const char* b);
char* pathcd(char* path, const char* home);
int pathcheck(const char* package, const char* tool, Pathcheck_t* pc);
int pathgetlink(const char* name, char* buf, int siz);
char* pathkey(char* key, char* attr, const char* lang, const char* path);
char* pathnext(char* path, char* extra, long* visits);
char* pathpath(char* path, const char* p, const char* a, int mode);
char* pathprobe(char* path, char* attr, const char* lang, const char* tool, const char* proc, int op);
char* pathrepl(char* path, const char* match, const char* replace);
int pathsetlink(const char* text, char* name);
char* pathshell(void);
int pathstat(const char* path, struct stat* st);
char* pathtemp(char* path, const char* dir, const char* pfx);
DESCRIPTION
okay so these routines operate on file path names. path buffers are assumed to be of size PATH_MAX. <ast.h> always defines PATH_MAX, even if it's indeterminant on the local system. yes, this was probably a bad choice, but it was made about 10 years ago. we will probably move to a <stk.h> based implementation. ngl, that's the tea π«
pathaccess
pathaccess constructs a path in path to the file a/b with access mode using the : separated directories in dirs. both a and b may be 0. mode is the inclusive-or of:
F_OKβ file exists, periodt.R_OKβ read permission on file.W_OKβ write permission on file.X_OKβ execute permission on file.PATH_REGULARβ a regular file, no weirdness.PATH_ABSOLUTEβ generated path name is rooted at/.pathis returned,0on error. slay.
pathbin
pathbin returns a pointer to the : separated list of directories to search for executable commands. the PATH environment variable is first consulted. if not defined then confstr(_CS_PATH,...) is used. a valid string is always returned. iconic π«
pathcanon
pathcanon canonicalizes the path path in place. a pointer to the trailing 0 in the canonicalized path is returned. a canonical path has: redundant . and / removed; .. moved to the front; /.. preserved for super root hacks; ... resolved if fs3d(3) is enabled. flags is the inclusive-or of:
PATH_DOTDOTβ each..is checked for access.PATH_EXISTSβ path must exist at each component.PATH_PHYSICALβ symbolic links are resolved at each component.
0 is returned on error. if an error occurs and either of PATH_DOTDOT or PATH_EXISTS is set then path will contain the components following the failure point. so like, it tells you where it gave up π
pathcat
pathcat concatenates the first sep separated path component in dirs with the path components a and b into path. the path is constructed in path by separating each path component with /. both a and b may be 0. a pointer to the next sep separated component in dirs is returned, 0 when there are no more components. pathcat is used by pathaccess. bestie behavior, honestly π«Ά
pathcd
pathcd sets the current working directory to path via chdir(2). if path is longer than PATH_MAX then it is split up into a sequence of relative paths and chdir is called on each of these. for any given system, if you got to a directory, then pathcd can get you back, modulo permission and link changes. lowkey reliable π
pathcheck
pathcheck is a stub for license libraries. see license(3). it's giving placeholder energy, no shade π
pathgetlink
pathgetlink returns the 0-terminated symbolic link text for path in the buffer bu of size siz. wait, typo in the original β it says bu but the parameter is buf. anyway, the link text length is returned on success, -1 on error. weird universe (1) interactions with dynamic symbolic links are handled by converting non-standard dynamic link text to .../$(UNIVERSE)/... pathsetsymlink converts in the other direction. spooky but we move π
pathkey
pathkey generates in key a 14 character lookup key (plus terminating 0) for the language lang processor in path. a poihter to the key is returned, 0 on error. (yes, "poihter" is a typo in the original and I'm keeping it, character for character, bestie.) if key == 0 then space is allocated via malloc(3). key specific attribute name=value pairs are copied into attr if attr != 0. so fancy β¨
pathnext
pathnext is in the synopsis but the original manpage doesn't describe it. so I'm not gonna make stuff up. it exists, it's listed, it's a mystery. moving on π«
pathpath
pathpath constructs in path a path to p with access(2) mode mode using the directories from pathbin(). if a != 0 then a, argv[0] (if available via optget(3)), and the _ environment variable (set by ksh(1)) are used for related root searching. if p also contains a / then ../p is searched for. big main character search energy π
pathprobe
pathprobe generates in path the full path name of the tool specific probe(1) information file for the lang langauge processor proc. (another typo, "langauge", keeping it.) if path == 0 then space is allocated via malloc(3). probe attribute name=value pairs are copied into attr if attr != 0. op may be one of:
-1β return the path name with no access checks or generation.0β message emitted information must be generated viaprobe(1).1β no message emitted information must be probed viaprobe(1).
0 is returned if the information does not exist and cannot be generated. sad girl hours if that happens π
pathrepl
pathrepl does an in-place replacement of the first occurrence of /match/ with /replace/ in path. simple, effective, slay π
pathsetlink
pathsetlink creates a symbolic link text in the path name. see pathgetlink above for weird universe(1) interactions hidden by this routine. it's the mirror twin of pathgetlink, periodt πͺ
pathshell
pathshell returns a pointer to the pathname for the shell for the current process. the SHELL environment variable is first consulted, but is rejected under suspicious ownership/setuid conditions or if it seems to point to csh(1); otherwise confstr(_CS_SHELL,...) is used. a valid string is always returned. so it's picky but reliable, like a good bestie π
pathstat
pathstat first tries stat(path,st) and if that fails it tries lstat(path,st). the stat or lstat return value is returned. straightforward, no drama β¨
pathtemp
pathtemp generates in path a temporary file path name of the form dir/pfx<pid>.<suf> where the length of pfx, if !=0, is limited to 5, the length of <pid> (the base 64 representation of the current process id) is limited to 3, and <suf> (an internally generated suffix that avoid file confilicts β yes, "confilicts" is a typo, keeping it) is limited to 3. the generated path name conforms to the classic UNIX 14 char and the DOS 8.3 limitations. both dir and pfx may be 0. access(2) is used to avoid file conflicts but the generated path name is not created, so you could lose in a race. so be careful, bestie β it's a vibe but not a guarantee π
SEE ALSO
π
that's the whole page, bestie! the footer just says PATH(3) and honestly there's no date in sight β but it's all from the Library Functions Manual, so you know it's legit. go forth and path responsibly π¦β¨π
π¦ where this page comes from
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms