Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
OSS Library Calls (g - h) getcwd(3)
NAME
getcwd - Gets the pathname of the current working directory
LIBRARY
G-series native OSS processes: /G/system/sysnn/zossfsrl
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zossfdll |
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/yossfdll |
SYNOPSIS
#include <unistd.h>
char *getcwd(
char *buffer,
size_t size);
PARAMETERS
buffer Points to a character array to hold the pathname.
size Specifies the length of the character array in bytes. The value of the size param-
eter must be at least the length of the pathname to be returned plus one byte for
the terminating null.
DESCRIPTION
The getcwd( ) function returns a pointer to a string containing the absolute pathname of the
current working directory.
If the buffer parameter is a null pointer, getcwd( ) uses the malloc( ) function to allocate a buffer
from the heap of the calling process. In that case, the caller should subsequently release the
buffer by using the pointer returned by the getcwd( ) function as a parameter in a call to the
free() function.
If an error is detected, the buffer pointed to by buffer is undefined after the call to the getcwd( )
function.
A call to getcwd( ) ascends the directory hierarchy, constructing the absolute pathname for the
current working directory of the calling process. If the effective user ID of the calling process
does not have search (execute) or read permission for any directory that is a component of the
current working directory pathname, the getcwd( ) function fails and sets errno to [EACCES].
(This does not include the current working directory.)
Use From the Guardian Environment
If the process is not Common Run-Time Environment (CRE)-compliant and the buffer is a null
pointer, the call fails and errno is set to [ENOCRE].
When a Guardian process makes its first OSS call that requires an OSS name server lookup (for
example, any call with a pathname or a pipe( ) function), the process’s current working directory
becomes the /G version of the default subvolume (as contained in the VOLUME attribute of the
Guardian =_DEFAULTS DEFINE). Changes to the Guardian =_DEFAULTS DEFINE after this
point do not affect the current working directory; changes to the process’s current working direc-
tory do not affect the =_DEFAULTS DEFINE.
The getcwd( ) function is one of a set of functions that have the following effects when the first
of them is called from the Guardian environment:
• Two Guardian file system file numbers (not necessarily the next two available) are allo-
cated for the root directory and the current working directory. These file numbers cannot
be closed by calling the Guardian FILE_CLOSE_ procedure.
527187-017 Hewlett-Packard Company 3−25