*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->Linux man pages -> getcwd (3)              
Title
Content
Arch
Section
 

GETCWD(3)

Contents


NAME    [Toc]    [Back]

       getcwd, get_current_dir_name, getwd - Get current working directory

SYNOPSIS    [Toc]    [Back]

       #include <unistd.h>

       char *getcwd(char *buf, size_t size);
       char *get_current_dir_name(void);
       char *getwd(char *buf);

DESCRIPTION    [Toc]    [Back]

       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    [Toc]    [Back]

       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    [Toc]    [Back]

       POSIX.1

SEE ALSO    [Toc]    [Back]

      
      
       chdir(2), free(3), malloc(3)



GNU				  1993-07-21			     GETCWD(3)
[ Back ]
 Similar pages
Name OS Title
cd Tru64 Changes the current working directory
fchdir FreeBSD change current working directory
chdir FreeBSD change current working directory
fchdir OpenBSD change current working directory
pwd IRIX Return the current working directory
pwd Linux print name of current/working directory
chdir NetBSD change current working directory
chdir OpenBSD change current working directory
fchdir NetBSD change current working directory
Cwd IRIX get pathname of current working directory
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service