RESOLVEPATH(3)

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

πŸ’… RESOLVEPATH(3) β€” Schily's LIBRARY FUNCTIONS 🌸

okay bestie, gather round, because this one's from Schily's LIBRARY FUNCTIONS and it's literally the glow-up your path names have been waiting for πŸ’–


✨ NAME ✨

resolvepath(), resolvenpath(), resolvefpath() β€” resolve all symbolic links of a path name πŸ¦‹

No cap, that's the whole vibe: you hand it a path, it hands you back a path with zero symlinks in it. Iconic.


πŸŽ€ SYNOPSIS πŸŽ€

#include <schily/schily.h>

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;

look at that alignment, whoever formatted this ate πŸ’…


🌈 DESCRIPTION 🌈

so 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 β€” literally symlink-free, a clean slate, main character energy ✨

  • path β€” a relative path name that is used as the input 🫢
  • buf β€” the buffer used for the result of the conversion πŸ’–
  • bufsiz β€” the size of the result buffer πŸŽ€

All ''.'' components are eliminated, and every non-leading ''..'' component is eliminated together with its preceding directory component. If leading ''..'' components reach to the root directory, they are replaced by ''/''. periodt β€” the .. drama gets cancelled out πŸ’€

resolvenpath() behaves like resolvepath() except that the file does not need to exist. ghosting the filesystem, honestly πŸ‘»

resolvefpath() takes an additional flags parameter from the set of flags from the following set:

  • 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 in case of an error, the contents of the result buffer is left in an intermediate state β€” so like, don't trust what's in there, it's giving half-finished group project 😭


πŸ”₯ ERRORS πŸ”₯

  • ERANGE β€” the path does not fit into the suplied buffer.
  • EFAULT β€” a null pointer was suplied as pathname.
  • EINVAL β€” an empty relative path was supplied.
  • other β€” any other value that may be a result of an underlying filesystem operation.

(and yes bestie the typos are in the original, I'm not fixing them, that's not my job ✨)


⭐ USAGE ⭐

Applications should not assume that the returned contents of the buffer are null-terminated. This is because the function resolvepath(3) may be the Solaris version if the program is compiled on Solaris. 🫠

ngl that's the kind of ✨platform surprise✨ that ruins your whole afternoon, so just... don't assume. check bufsiz, live your truth, be free πŸ¦‹

🧚 SEE ALSO 🧚

yes, it's citing itself, we love a self-aware icon πŸ™ˆ


πŸ’€ NOTES πŸ’€

none

that's it. that's the note. short and iconic, honestly πŸ‘‘


anyway that's the whole page, bestie β€” go forth and resolve those paths, you're gonna do amazing πŸŽ€

this masterpiece was brought to you by Joerg Schilling, dated 2022/09/09, in the year of our lord 🌸 stay hydrated, back up your buffers, and remember: no cap, always check that return value πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from