[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

getcwd Subroutine

Purpose

Gets the path name of the current directory.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>
char *getcwd (Buffer, Size)
char *Buffer;
size_t Size;

Description

The getcwd subroutine places the absolute path name of the current working directory in the array pointed to by the Buffer parameter, and returns that path name. The size parameter specifies the size in bytes of the character array pointed to by the Buffer parameter.

Parameters

Buffer Points to string space that will contain the path name. If the Buffer parameter value is a null pointer, the getcwd subroutine, using the malloc subroutine, obtains the number of bytes of free space as specified by the Size parameter. In this case, the pointer returned by the getcwd subroutine can be used as the parameter in a subsequent call to the free subroutine. Starting the getcwd subroutine with a null pointer as the Buffer parameter value is not recommended.
Size Specifies the length of the string space. The value of the Size parameter must be at least 1 greater than the length of the path name to be returned.

Return Values

If the getcwd subroutine is unsuccessful, a null value is returned and the errno global variable is set to indicate the error. The getcwd subroutine is unsuccessful if the Size parameter is not large enough or if an error occurs in a lower-level function.

Error Codes

If the getcwd subroutine is unsuccessful, it returns one or more of the following error codes:

EACCES Indicates that read or search permission was denied for a component of the path name
EINVAL Indicates that the Size parameter is 0 or a negative number.
ENOMEM Indicates that insufficient storage space is available.
ERANGE Indicates that the Size parameter is greater than 0, but is smaller than the length of the path name plus 1.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The getwd subroutine, malloc subroutine.

Files, Directories, and File Systems for Programmers in AIX General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]