Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4 |
both |
#define _XOPEN_SOURCE
#include <unistd.h>
int chroot(const char *path);
The path argument points to a path name naming a directory. The chroot() function causes the named directory to become the root directory, that is the starting point for path searches for path names beginning with /. The process's working directory is unaffected by chroot(). Only a superuser can request chroot().
The dot-dot entry in the root directory is interpreted to mean the root directory. Thus, dot-dot cannot be used to access files outside the subtree rooted at the root directory.
This function is kept for historical reasons. It was part of the Legacy Feature in Single UNIX Specification, Version 2, but has been withdrawn and is not supported as part of Single UNIX Specification, Version 3.
If it is necessary to continue using this function in an application written for Single UNIX Specification, Version 3, define the feature test macro _UNIX03_WITHDRAWN before including any standard system headers. The macro exposes all interfaces and symbols removed in Single UNIX Specification, Version 3.
If successful, chroot() changes the root directory, and returns 0.