canonicalize_file_name(3)

πŸ’– canonicalize_file_name(3) πŸ’–

okay so bestie, welcome to the glow-up page for canonicalize_file_name β€” it lives in the Library Functions Manual (section 3, the library girlies) and honestly? she's giving "short but does the most". let's get into it πŸŽ€


✨ NAME ✨

canonicalize_file_name β€” return the canonicalized absolute pathname


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc) β€” yeah, she's in libc, we been knew πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <stdlib.h>

char *canonicalize_file_name(const char *path);

quick note bestie: that #define _GNU_SOURCE line is not optional, it's how you unlock her (peep feature_test_macros(7) for the deets), and the include is <stdlib.h>. do not skip either one, i'm literally begging πŸ™ˆ


🌸 DESCRIPTION 🌸

So canonicalize_file_name() hands you back a null-terminated string holding the canonicalized absolute pathname that corresponds to path. ✨

And in that returned string, the way that everything gets cleaned up?? iconic:

  • symbolic links are resolved πŸ”—
  • . and .. pathname components are resolved too
  • consecutive slash (/) characters get replaced by a single slash

The returned string is dynamically allocated</> by canonicalize_file_name() itself, so bestie, the caller should deallocate it with free(3) when it is no longer required. if you don't, that's a leak, and that's not the vibe πŸ’€

also lowkey the cutest part: the call

canonicalize_file_name(path)

is equivalent to the call

realpath(path, NULL);

same energy, same result. she's just a little alias-coded 🫢


πŸŽ€ RETURN VALUE πŸŽ€

  • On success, canonicalize_file_name() returns a null-terminated string. slay πŸ’–
  • On error (e.g., a pathname component is unreadable or does not exist 😭), canonicalize_file_name() returns NULL and sets errno to indicate the error.
ok so if you get NULL back, do NOT just keep vibing β€” check errno. she's trying to tell you something.

🌈 ERRORS 🌈

See realpath(3). that's the whole section, go look over there, she's got the receipts πŸ“œ


πŸ‘‘ ATTRIBUTES πŸ‘‘

For an explanation of the terms used in this section, see attributes(7).

  • Interface: canonicalize_file_name()
    • Attribute: Thread safety
    • Value: MT-Safe

yes bestie, MT-Safe β€” she can hang out with all your threads at once, no drama, no chaos, we love a multithread-safe queen πŸ”₯


⭐ STANDARDS ⭐

GNU. that's it, that's the standard. (so if you're on non-GNU, vibe check first πŸ‘€)


πŸ’œ SEE ALSO πŸ’œ


and that's the whole page, no cap 🧚

mwah β€” this was canonicalize_file_name(3) from Linux man-pages 6.20, dated 2026-02-08. go free your strings, bestie. periodt. πŸ’…βœ¨πŸ“

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms