Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 8

getcwd()

Get the name of the current working directory

Synopsis:

#include <unistd.h>

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

Arguments:

buffer
NULL, or a pointer to a buffer where the function can store the directory name.
size
The size of the buffer, in bytes.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The getcwd() function returns the name of the current working directory. buffer is a pointer to a buffer of at least size bytes where the NUL-terminated name of the current working directory will be placed.

The maximum size that might be required for buffer is PATH_MAX + 1 bytes. See <limits.h>.


Note: POSIX doesn't specify what should happen if you call getcwd( NULL, 0). The Neutrino version (like many others) allocates a buffer for the name of the directory; it's up to your application to free the buffer when you no longer need it.

Returns:

The address of the string containing the name of the current working directory, or NULL if an error occurred (errno is set).

Errors:

EINVAL
The argument size is negative or 0.
ELOOP
Too many levels of symbolic links.
ENOSYS
The getcwd() function isn't implemented for the filesystem specified in the current working directory.
ERANGE
The buffer is too small (as specified by size) to contain the name of the current working directory.

Examples:

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

int main( void )
{
    char* cwd;
    char buff[PATH_MAX + 1];

    cwd = getcwd( buff, PATH_MAX + 1 );
    if( cwd != NULL ) {
        printf( "My working directory is %s.\n", cwd );
    }

    return EXIT_SUCCESS;
}

produces the output:

My working directory is /home/bill.

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

There is only one current working directory per process. In a multithreaded application, any thread calling chdir() will change the current working directory for all threads in that process.

See also:

chdir(), errno, fchdir(), mkdir(), rmdir()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 207

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/g/getcwd.html on line 207