13.1 Current Working Directory

The current working directory is a POSIX notion (but also used by ANSI functions, which are often build on top of POSIX) and provides for state that indicates a current file system path respective to which all file and directory operations are reckoned.

The following standard POSIX interfaces consume the current working directory:

access

mkdir

chmod

mkfifo

chdir

rmdir

creat

stat

getcwd

umask

open

unlink

opendir

utime

mkdir

The following standard ANSI interfaces consume the current working directory:

fopen

rename

remove

The following NovellĀ® additions to POSIX and ANSI interfaces manipulate or use the current working directory:

chdir2

setcwd

getcwdpath

setcwd2

The Novell additions solve a couple of unique problems when running on the NetWare operating system. In implementing remote NetWare file system access as well as authenticated access to the local file system, LibC natively uses NKS, which uses a path context rather than a current working directory. A path context contains the current working directory, but it also contains additional information such as name space and user identity, which are important to LibC and the NetWare operating system (see Path Context). The setcwd and setcwd2 functions allow you to insert this additional information into the cwd and then continue using ANSI and POSIX functions. LibC transparently uses this additional information when it is needed. For lack of arguments in standard C functions, these problems cannot be solved in an explicit way for ANSI and POSIX functions.

LibC requires two functions for changing and setting the current working directory because a virtual machine can have

The chrdir2 and setcwd2 functions allow you to change or set the current working directory for a single thread, and the chrdir and setcwd functions allow you to change or set the current working directory for all threads in the virtual machine.

The getcwdpath function solves the NetWare full path problem. ANSI and POSIX functions assume that a full path includes just directory names from the root to the target directory. Full NetWare paths can also include the server and the volume name, and getcwdpath retrieves this additional information.

By using NXCreatePathContext, setcwd2, chdir2, and getcwdpath, it is possible to make a round trip from path to current working directory and back, something that would not be possible using only getcwd.