RESOLVEPATH(3)

πŸ“¦
version 2022.10.16 Β· 2 versions
, in opensuse-leap 16.0

🌸 RESOLVEPATH(3) β€” SchilyΒ΄s LIBRARY FUNCTIONS 🌸

okay bestie, listen up πŸ’– this page is all about three little functions that take your messy path name and un-mess it β€” resolvepath(), resolvenpath(), and resolvefpath(). their whole entire job? resolve all symbolic links of a path name. no cap. ✨


✨ NAME ✨

resolvepath(), resolvenpath(), resolvefpath() β€” resolve all symbolic links of a path name 🫢


πŸŽ€ SYNOPSIS πŸŽ€

first, the glow-up ritual (aka the include):

#include <schily/schily.h>

then the three icons themselves, exactly as they live in the header:

int
resolvepath(path, buf, bufsiz)
        const char    *path;
              char    *buf;
              size_t  bufsiz;
int
resolvenpath(path, buf, bufsiz)
        const char    *path;
              char    *buf;
              size_t  bufsiz;
int
resolvefpath(path, buf, bufsiz, flags)
        const char    *path;
              char    *buf;
              size_t  bufsiz;
              int     flags;

πŸ’… DESCRIPTION πŸ’…

resolvepath() β€” the main character

resolvepath() takes a relative path name and resolves all symbolic links in the path name. the result is a path name that is free of symbolic links. πŸ’«

  • path β€” the relative path name used as the input
  • buf β€” the buffer used for the result of the conversion
  • bufsiz β€” the size of the result buffer

and the glow-up rules, lowkey iconic:

  • all "." components are eliminated
  • every non-leading ".." component is eliminated together with its preceding directory component
  • if leading ".." components reach the root directory, they're replaced by "/" πŸ‘‘

resolvenpath() β€” same vibes, less commitment

resolvenpath() behaves like resolvepath() except that the file does not need to exist. that's it. that's the tweet. πŸ™ˆ

resolvefpath() β€” the one with extra flags

resolvefpath() takes an additional flags parameter, pulled from this set of flags:

  • RSPF_EXIST β€” all path components must exist. 🫑
  • RSPF_NOFOLLOW_LAST β€” don't follow symbolic links in the last path component. πŸ™…β€β™€οΈ

πŸ”₯ RETURN VALUE πŸ”₯

upon successful completion, resolvepath(), resolvenpath() and resolvefpath() return the number of bytes placed in the buffer. slay. ✨

otherwise, -1 is returned and errno is set to indicate the error. and heads up: in case of an error, the contents of the result buffer is left in an intermediate state β€” so like, don't trust it, it's mid. 😭


πŸ’€ ERRORS πŸ’€

  • ERANGE β€” the path does not fit into the supplied buffer. too big for the bag, honestly. πŸŽ’
  • EFAULT β€” a null pointer was supplied as pathname. bestie. why. πŸ™ˆ
  • EINVAL β€” an empty relative path was supplied. nothing to work with! 🫠
  • other β€” any other value that may be a result of an underlying filesystem operation. mystery box energy. 🎁

🌈 USAGE 🌈

applications should not assume that the returned contents of the buffer are null-terminated. 🚨

why, you ask? because the function resolvepath(3) may be the Solaris version if the program is compiled on Solaris. plot twist fr fr. 😳


πŸ’œ SEE ALSO πŸ’œ


🧚 NOTES 🧚

none. literally none. that's the whole note. πŸ’€


okay that's the whole page bestie, you ate that πŸ“ mwah πŸ’‹ β€” this masterpiece of a man page is brought to you by Joerg Schilling, dated 2022/09/09, living its best life as RESOLVEPATH(3) in SchilyΒ΄s LIBRARY FUNCTIONS. periodt. πŸ‘‘

πŸ“¦ where this page comes from