Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

getcwd(3) [osf1 man page]

getcwd(3)						     Library Functions Manual							 getcwd(3)

NAME
getcwd - Gets the pathname of the current directory LIBRARY
Standard C Library (libc) System V Library (libsysv) SYNOPSIS
Standard C Library: #include <unistd.h> char *getcwd( char *buffer, size_t size); System V Library: char *getcwd( char *buffer, int size); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: getcwd() - libc version: XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Points to a string space to hold the pathname. Specifies the length of the string space in bytes. The value of the size parameter 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 directory. The getwd() function is called to obtain the pathname. [Tru64 UNIX] If the buffer parameter is a null pointer, the getcwd() function, using the malloc() function, obtains the number of bytes of free space as specified by the size parameter. In this case, the pointer returned by the getcwd() function can be used as the parameter in a subsequent call to the free() function. NOTES
[Tru64 UNIX] The getcwd() function is supported for multithreaded applications. RETURN VALUES
Upon successful completion, getcwd() returns the buffer parameter. Otherwise, a null value is returned and errno is set to indicate the error. ERRORS
The getcwd() function sets errno to the specified values for the following conditions: Read or search permission was denied for a component of the pathname. The size parameter is zero. [Tru64 UNIX] The size parameter is less than or equal to zero (for the libsys5 version of getcwd() only). The size parameter is greater than zero, but is smaller than the length of the pathname + 1. The requested amount of memory could not be allocated. RELATED INFORMATION
Functions: malloc(3), getwd(3) Standards: standards(5) delim off getcwd(3)

Check Out this Related Man Page

GETCWD(3)						   BSD Library Functions Manual 						 GETCWD(3)

NAME
getcwd, getwd -- get working directory pathname LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <unistd.h> char * getcwd(char *buf, size_t size); char * getwd(char *buf); DESCRIPTION
The getcwd() function copies the absolute pathname of the current working directory into the memory referenced by buf and returns a pointer to buf. The size argument is the size, in bytes, of the array referenced by buf. If buf is NULL, space is allocated as necessary to store the pathname. This space may later be free(3)'d. The function getwd() is a compatibility routine which calls getcwd() with its buf argument and a size of MAXPATHLEN (as defined in the include file <sys/param.h>). Obviously, buf should be at least MAXPATHLEN bytes in length. These routines have traditionally been used by programs to save the name of a working directory for the purpose of returning to it. A much faster and less error-prone method of accomplishing this is to open the current directory ('.') and use the fchdir(2) function to return. RETURN VALUES
Upon successful completion, a pointer to the pathname is returned. Otherwise a NULL pointer is returned and the global variable errno is set to indicate the error. In addition, getwd() copies the error message associated with errno into the memory referenced by buf. ERRORS
The getcwd() function will fail if: [EACCES] Read or search permission was denied for a component of the pathname. [EINVAL] The size argument is zero. [ENOENT] A component of the pathname no longer exists. [ENOMEM] Insufficient memory is available. [ERANGE] The size argument is greater than zero but smaller than the length of the pathname plus 1. SEE ALSO
chdir(2), fchdir(2), malloc(3), strerror(3) STANDARDS
The getcwd() function conforms to ISO/IEC 9945-1:1990 (``POSIX.1''). The ability to specify a NULL pointer and have getcwd() allocate memory as necessary is an extension. HISTORY
The getwd() function appeared in 4.0BSD. BUGS
The getwd() function does not do sufficient error checking and is not able to return very long, but valid, paths. It is provided for compat- ibility. BSD
November 24, 1997 BSD
Man Page