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

  man pages->IRIX man pages -> getcwd (3c)              


getcwd(3C)							    getcwd(3C)

NAME    [Toc]    [Back]

     getcwd - get pathname of current working directory

SYNOPSIS    [Toc]    [Back]

     #include <unistd.h>

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

DESCRIPTION    [Toc]    [Back]

     getcwd returns a pointer to the current directory pathname.  The value of
     size must be at least one greater than the	length of the pathname to be

     If	buf is not NULL, the pathname will be stored in	the space pointed to
     by	buf.

     If	buf is a NULL pointer, getcwd will obtain size bytes of	space using
     malloc(3C).  In this case,	a subsequent call to free should be made using
     the pointer returned by getcwd as the argument. If	size is	less than
     zero, then	getcwd will obtain an appropriate amount of space.  Passing a
     negative size and a non-NULL buf argument will lead to undefined results.

     getcwd will fail if one or	more of	the following are true:

     EACCES	 A parent directory cannot be read to get its name.

     EINVAL	 size is equal to 0.

     ERANGE	 size is less than the length of the pathname plus 1.

EXAMPLE    [Toc]    [Back]

     Here is a program that prints the current working directory.

	  #include <unistd.h>
	  #include <stdio.h>

	       char *cwd;
	       if ((cwd	= getcwd(NULL, 64)) == NULL)
	       (void)printf("%s\n", cwd);

									Page 1

getcwd(3C)							    getcwd(3C)


DIAGNOSTICS    [Toc]    [Back]

     Returns NULL with errno set if size is not	large enough, or if an error
     occurs in a lower-level function.

NOTES    [Toc]    [Back]

     getcwd uses the end part of the buffer ( buf + size - 1) as temporary
     space.  Be	sure that the size argument accurately reflects	the space
     allocated to the buffer.

									PPPPaaaaggggeeee 2222
[ Back ]
 Similar pages
Name OS Title
getwd IRIX get current working directory pathname
pwd Tru64 Displays the pathname of the current working directory
getcwd FreeBSD get working directory pathname
getcwd OpenBSD get working directory pathname
getwd OpenBSD get working directory pathname
getwd NetBSD get working directory pathname
getcwd NetBSD get working directory pathname
getwd FreeBSD get working directory pathname
pxfgetcwd IRIX Gets the pathname of the working directory
cd Tru64 Changes the current working directory
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service