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 PTC MKS Toolkit UNIX to Windows Porting Guide for more information.

Path names are returned as multibyte sequences and are converted from Unicode (UTF-16) before returning from Win32. The conversion is either performed based on the current thread locale, set using uselocale() or the process locale as set by a call to setlocale(), and overridden by _NutConf() _NC_SET_ANSI_LOCALE and _NC_SET_UTF8_LOCALE options. Under all other conditions, the multibyte sequences are considered to be from the ANSI code page for the current windows system locale.


AVAILABILITY

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


SEE ALSO

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


PTC MKS Toolkit 10.4 Documentation Build 39.