| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- get pathname of current working directory
#include <unistd.h>char *getcwd(char *buf,size_tsize);
Thegetcwd() function places an absolute pathname of the current working directoryin the array pointed to bybuf, and returnsbuf. The pathnamecopied to the array contains no components that are symbolic links. Thesize argument is the size in bytes of the character array pointedto bybuf and must be at least one greater than thelength of the pathname to be returned.
Ifbuf is not a null pointer, the pathname is stored inthe space pointed to bybuf.
Ifbuf is a null pointer,getcwd() obtainssize bytes of spaceusingmalloc(3C). The pointer returned bygetcwd() can be used as the argumentin a subsequent call tofree().
Upon successful completion,getcwd() returns thebuf argument. Ifbuf is aninvalid destination buffer address,NULL is returned anderrno is set toEFAULT. Otherwise, a null pointer is returned anderrno is set to indicatethe error.
Thegetcwd() function will fail if:
Thebuf argument is an invalid destination buffer address.
Thesize argument is equal to 0.
Thesize argument is greater than 0 and less than the length of the pathname plus 1.
Thegetcwd() function may fail if:
A parent directory cannot be read to get its name.
Insufficient storage space is available.
Example 1 Determine the absolute pathname of the current working directory.
The following example returns a pointer to an array that holds theabsolute pathname of the current working directory. The pointer is returned intheptr variable, which points to thebuf array where the pathnameis stored.
#include <stdlib.h>#include <unistd.h>...long size;char *buf;char *ptr;size = pathconf(".", _PC_PATH_MAX);if ((buf = (char *)malloc((size_t)size)) != NULL) ptr = getcwd(buf, (size_t)size);...Example 2 Print the current working directory.
The following example prints the current working directory.
#include <unistd.h>#include <stdio.h>main( ){ char *cwd; if ((cwd = getcwd(NULL, 64)) == NULL) { perror("pwd"); exit(2); } (void)printf("%s\n", cwd); free(cwd); /* free memory allocated by getcwd() */ return(0);}Applications should exercise care when usingchdir(2) in conjunction withgetcwd(). Thecurrent working directory is global to all threads within a process. If morethan one thread callschdir() to change the working directory, a subsequentcall togetcwd() could produce unexpected results.
Seeattributes(5) for descriptions of the following attributes:
|
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |