OS/161 Reference Manual


__getcwd - get name of current working directory (backend)


Standard C Library (libc, -lc)


#include <unistd.h>

__getcwd(char *buf, size_t buflen);


The name of the current directory is computed and stored in buf, an area of size buflen. The length of data actually stored, which must be non-negative, is returned.

Note: this call behaves like read - the name stored in buf is not 0-terminated.

This function is not meant to be called except by the C library; application programmers should use getcwd instead.

__getcwd (like all system calls) should be atomic. In practice, because of complications associated with locking both up and down trees, it often isn't quite. Note that the kernel is not obliged to (and generally cannot) make the __getcwd call atomic with respect to other threads in the same process accessing the transfer buffer during the operation.

Return Values

On success, __getcwd returns the length of the data returned. On error, -1 is returned, and errno is set according to the error encountered.


The following error codes should be returned under the conditions given. Other error codes may be returned for other cases not mentioned here.
  ENOENT A component of the pathname no longer exists.
EIO A hard I/O error occurred.
EFAULT buf points to an invalid address.