CHDIR(3P)

πŸ’– CHDIR(3P) β€” bestie we're MOVING πŸ’–

okay so real talk, this page lives in the POSIX Programmer's Manual, and it's giving ✨ official standards energy ✨. Just a heads up before we dive in: the Linux implementation of this interface may differ, so if you're on Linux you lowkey need to go check the corresponding Linux manual page for the deets on Linux behavior. Also possible: the interface just isn't implemented on Linux at all. πŸ™ˆ Not me warning you first, that's just being a good friend.


🌸 PROLOG 🌸

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.


πŸ‘‘ NAME πŸ‘‘

chdir β€” change working directory. That's it, that's the whole vibe. You're packing up and moving somewhere new. 🧳


✨ SYNOPSIS ✨

#include <unistd.h>

int chdir(const char *path);

πŸ¦‹ DESCRIPTION πŸ¦‹

The chdir() function shall cause the directory named by the pathname pointed to by the path argument to become the current working directory. Like, that's your new home base, bestie. 🏠

And what does "current working directory" even mean, you ask? It's the starting point for path searches for pathnames that don't begin with '/'. So if you type a relative path, the search literally starts from wherever you just chdir()'d into. main character location energy fr fr. πŸ’…


πŸ’… RETURN VALUE πŸ’…

  • Slay: on successful completion, 0 shall be returned. ✨
  • Not slay: otherwise, -1 shall be returned, and the current working directory shall remain unchanged (so you're not left homeless, okurrr), and errno shall be set to indicate the error.

πŸ’€ ERRORS πŸ’€

The chdir() function shall fail if:

  • EACCES β€” Search permission is denied for any component of the pathname. 🚫
  • ELOOP β€” A loop exists in symbolic links encountered during resolution of the path argument. πŸŒ€ (a symlink ouroboros, literally)
  • ENAMETOOLONG β€” The length of a component of a pathname is longer than {NAME_MAX}. 😭
  • ENOENT β€” A component of path does not name an existing directory, or path is an empty string. πŸ‘»
  • ENOTDIR β€” A component of the pathname names an existing file that is neither a directory nor a symbolic link to a directory. like bestie that's a file, not a folder, read the room. πŸ“„

The chdir() function may fail if:

  • ELOOP β€” More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument. πŸŒ€πŸŒ€
  • ENAMETOOLONG β€” The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}. 😡
Heads up: the following sections are informative. They're the ✨lore✨ not the law.

🌈 EXAMPLES 🌈

πŸŽ€ Changing the Current Working Directory πŸŽ€

The following example makes the value pointed to by directory, /tmp, the current working directory. No cap.

#include <unistd.h>
...
char *directory = "/tmp";
int ret;

ret = chdir (directory);

🫢 APPLICATION USAGE 🫢

None.


🧠 RATIONALE 🧠

The chdir() function only affects the working directory of the current process. That's it. Just you. Not your friends, not the shell next door, not the whole system. individual queen behavior. πŸ‘‘


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ”₯ SEE ALSO πŸ”₯

  • getcwd()
  • The Base Definitions volume of POSIX.1‐2017, <unistd.h>

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.

In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document (so if there's beef, the original wins, periodt). The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html.


okay that's the whole page bestie, ily, go change some directories responsibly πŸ’–βœ¨

IEEE/The Open Group, 2017 β€” yeah that's the source and the date, mwah, sign-off complete, πŸŽ€ bye πŸŽ€

πŸ“¦ where this page comes from