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()returnsNULLand setserrnoto indicate the error.
ok so if you getNULLback, do NOT just keep vibing β checkerrno. 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
- Copyright 2013, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms