#include <unistd.h> char *getcwd(char *buf, size_t size);Service Program Name: QP0LLIB2
The getcwd() function determines the absolute path name of the current directory and stores it in buf. The components of the returned path name are not symbolic links.
The access time of each directory in the absolute path name of the current directory (excluding the current directory itself) is updated.
If buf is a NULL pointer, getcwd() returns a NULL pointer and the [EINVAL] error.
See QlgGetcwd()--Get Current Directory for a description and an example of supplying the buf in any CCSID.
Note: Adopted authority is not used.
Authorization Required for getcwd()
Object Referred to | Authority Required | errno |
---|---|---|
Each directory in the path name preceding the current directory | *RX | EACCES |
Current directory | *X | EACCES |
Note: QDLS File
System Differences
If the current directory is an immediate subdirectory of /QDLS (that is, at the next level below /QDLS in the directory hierarchy), the user must have *RX (*USE) authority to the directory. Otherwise, the QDLS authority requirements are the same as shown above. |
Note: If buf is a NULL pointer, getcwd() returns a NULL pointer.
If getcwd() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EACCES] |
If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems. |
[EAGAIN] | |
[EBADFID] | |
[EBADNAME] | |
[EBUSY] | |
[ECONVERT] | |
[EDAMAGE] | |
[EEXIST] | |
[EFAULT] | |
[EINTR] | |
[EINVAL] | |
[EIO] | |
[EMFILE] | |
[ENAMETOOLONG] | |
[ENFILE] | |
[ENOENT] | |
[ENOMEM] | |
[ENOSPC] | |
[ENOTAVAIL] | |
[ENOTSAFE] | |
[ENOTSUP] | |
[ERANGE] |
The value of an argument is too small, or a result too large. For example, the size argument is too small. It is greater than zero but smaller than the length of the path name plus a NULL character. |
[EROOBJ] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[EUNKNOWN] |
If interaction with a file server is required to access the object, errno could indicate one of the following errors:
Error condition | Additional information |
---|---|
[EADDRNOTAVAIL] | |
[ECONNABORTED] | |
[ECONNREFUSED] | |
[ECONNRESET] | |
[EHOSTDOWN] | |
[EHOSTUNREACH] | |
[ENETDOWN] | |
[ENETRESET] | |
[ENETUNREACH] | |
[ESTALE] |
If you are accessing a remote file through the Network File System, the file may have been deleted at the server. |
[ETIMEDOUT] | |
[EUNATCH] |
The following messages may be sent from this function:
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
If the directory exists on a volume formatted in Universal Disk Format (UDF), the authorization that is checked for the directory and preceding directories in the path name follows the rules described in Authorization Required for getcwd(). If the directory exists on a volume formatted in some other media format, no authorization checks are made on the directory or preceding directories. The volume authorization list is checked for *USE authority regardless of the volume media format.
See Code disclaimer information for information pertaining to code examples.
The following example determines the current directory:
#include <unistd.h> #include <stdio.h> main() { char cwd[1024]; if (chdir("/tmp") != 0) perror("chdir() error()"); else { if (getcwd(cwd, sizeof(cwd)) == NULL) perror("getcwd() error"); else printf("current working directory is: %s\n", cwd); } }
Output:
current working directory is: /tmp
Top | UNIX-Type APIs | APIs by category |