Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
getcwd(3)
Edit
PageHistory
Diff
Info
LikePages
GETCWD !!!GETCWD NAME SYNOPSIS DESCRIPTION RETURN VALUE CONFORMING TO SEE ALSO ---- !!NAME getcwd, get_current_dir_name, getwd - Get current working directory !!SYNOPSIS __#include __''buf''__, size_t__ ''size''__); char *get_current_dir_name(void); char *getwd(char *__''buf''__); __ !!DESCRIPTION The __getcwd__() function copies an absolute pathname of the current working directory to the array pointed to by ''buf'', which is of length ''size''. If the current absolute path name would require a buffer longer than ''size'' elements, __NULL__ is returned, and ''errno'' is set to __ERANGE__; an application should check for this error, and allocate a larger buffer if necessary. If ''buf'' is NULL, the behaviour of __getcwd__() is undefined. As an extension to the POSIX.1 standard, Linux (libc4, libc5, glibc) __getcwd()__ allocates the buffer dynamically using __malloc()__ if ''buf'' is __NULL__ on call. In this case, the allocated buffer has the length ''size'' unless ''size'' is zero, when ''buf'' is allocated as big as necessary. It is possible (and, indeed, advisable) to __free()__ the buffers if they have been obtained this way. __get_current_dir_name__, which is only prototyped if ___GNU_SOURCE__ is defined, will malloc(3) an array big enough to hold the current directory name. If the environment variable __PWD__ is set, and its value is correct, then that value will be returned. __getwd__, which is only prototyped if ___BSD_SOURCE__ or ___XOPEN_SOURCE_EXTENDED__ is defined, will not malloc(3) any memory. The ''buf'' argument should be a pointer to an array at least __PATH_MAX__ bytes long. __getwd__ does only return the first __PATH_MAX__ bytes of the actual pathname. !!RETURN VALUE __NULL__ on failure (for example, if the current directory is not readable), with ''errno'' set accordingly, and ''buf'' on success. The contents of the array pointed to by ''buf'' is undefined on error. !!CONFORMING TO POSIX.1 !!SEE ALSO chdir(2), free(3), malloc(3) ----
5 pages link to
getcwd(3)
:
Man3g
realpath(3)
slrn(1)
fchdir(2)
chdir(2)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.