getcwd()

get path name of current working directory 

Function


SYNOPSIS

#include <unistd.h>

char *getcwd(char *buf, size_t size);


DESCRIPTION

The getcwd() function gets the path name of the current working directory. If a buffer is specified, the path name is placed in that buffer, and the address of the buffer is returned. Otherwise, getcwd() allocates space for the path name and returns a pointer to that buffer. In that instance, the user is responsible for deleting the storage when it is no longer needed by calling free() with the pointer returned by getcwd().


PARAMETERS

buf 

Points to the buffer to copy the current working directory to, or NULL if getcwd() should allocate the buffer.

size 

Is the size, in bytes, of the array of characters that buf points to.


RETURN VALUES

If successful, getcwd() returns buf, if a non-null pointer was specified, or the address of the allocated memory otherwise. On failure, it returns a null pointer and sets errno to one of the following values:

EACCES 

A parent directory cannot be read to get its name.

Read or search permission was denied for a component of the path name.

EINVAL 

The size parameter is zero, and the buf parameter is a non-null pointer.

ENOMEM 

Insufficient memory exists to allocate a buffer to hold the path name.

ERANGE 

size is less than 0 or is greater than zero but less than the length of the path name plus 1.


CONFORMANCE

POSIX.1 (1996).


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The returned path name is in NuTCRACKER Platform format. You can use _NutPathToWin32() or _NutPathToWin32FS() to convert the name to another format if needed. Refer to Path Names in the Windows Concepts chapter of the MKS Toolkit UNIX to Windows Porting Guide for more information.


AVAILABILITY

MKS Toolkit for Professional Developers
MKS Toolkit for Enterprise Developers
MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_NutPathToWin32(), _NutPathToWin32FS(), free(), malloc()


MKS Toolkit 9.3 Documentation Build 6.