www.delorie.com/djgpp/doc/libc/libc_386.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

getcwd

Syntax

 
#include <unistd.h>

char *getcwd(char *buffer, int max);

Description

Get the current directory. The return value includes the drive specifier.

If buffer is NULL, getcwd allocates a buffer of size max with malloc. This is an extension of the POSIX standard, which is compatible with the behaviour of glibc (the C library used on Linux).

This call fails if more than max characters are required to specify the current directory.

Return Value

The buffer, either buffer or a newly-allocated buffer, or NULL on error.

Portability

ANSI/ISO C No
POSIX 1003.2-1992; 1003.1-2001 (see note 1)

Notes:

  1. The behaviour when buffer is NULL is unspecified for POSIX.

Example

 
char *buf = (char *)malloc(PATH_MAX);
if (buf && getcwd(buf, PATH_MAX))
{
  printf("cwd is %s\n", buf);
  free(buf);
}


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2004   by DJ Delorie     Updated Apr 2004