CHDIR(2)
π CHDIR(2) β System Calls Manual π
okay bestie, welcome to CHDIR(2), the chdir and fchdir system calls, straight outta the System Calls Manual. this is the page that tells you how to move your whole vibe to a different directory. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
chdir, fchdir β change current working directory
π LIBRARY π
Standard C Library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <unistd.h>
int
chdir(const char *path);
int
fchdir(int fd);
π DESCRIPTION π
so the path argument points to the pathname of a directory. the chdir() system call causes the named directory to become the current working directory β that is, the starting point for path searches of pathnames not beginning with a slash, /. like, it's your new home base for everything relative. no cap. π β¨
the fchdir() system call causes the directory referenced by fd to become the current working directory β the starting point for path searches of pathnames not beginning with a slash, /. same energy, but you're coming in through a file descriptor instead of a string. iconic.
and in order for a directory to become the current directory, a process must have execute (search) access to the directory. no permission, no entry. that's the vibe check, and you did not pass it. π
π RETURN VALUES π
upon successful completion, the value 0 is returned β¨ otherwise the value -1 is returned and the global variable errno is set to indicate the error. so, like, 0 = slay, -1 = check errno, bestie.
π ERRORS π
the chdir() system call will fail and the current working directory will be unchanged if one or more of the following are true:
[ENOTDIR]β a component of the path prefix is not a directory. rude.[ENAMETOOLONG]β a component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. it's giving excessive, honestly.[ENOENT]β the named directory does not exist. she's not there. never was. π«[ELOOP]β too many symbolic links were encountered in translating the pathname. the symlinks are linking the symlinks, it's a whole situation.[EACCES]β search permission is denied for any component of the path name.[EFAULT]β thepathargument points outside the process's allocated address space. out of bounds, literally.[EIO]β an I/O error occurred while reading from or writing to the file system.[EINTEGRITY]β corrupted data was detected while reading from the file system. the data is not okay. π
the fchdir() system call will fail and the current working directory will be unchanged if one or more of the following are true:
[EACCES]β search permission is denied for the directory referenced by the file descriptor.[ENOTDIR]β the file descriptor does not reference a directory.[EBADF]β the argumentfdis not a valid file descriptor.
note the pattern: if it fails, your cwd stays exactly where it was. no half-moves, no chaos. very demure, very mindful.
π SEE ALSO π
β STANDARDS β
the chdir() system call is expected to conform to ISO/IEC 9945-1:1990 (βPOSIX.1β). periodt.
π¦ HISTORY π¦
the chdir() system call appeared in Version 1 AT&T UNIX. the fchdir() system call appeared in 4.2BSD. ancient icons, both of them. π
and that's the whole page, bestie! this beauty came to you from Debian, dated March 30, 2020 β go change directories responsibly, mwah π β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms