Borland C++ reference

getcwd

raw OCR

Gets current working directory.

Defined in header <dir.h>

Syntax

#include <dir.h>
char *getcwd(char  *buf, int buflen);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

getcwd gets the full path name (including the drive) of the current working directory, up to buflen bytes long and stores it in buf. If the full path name length (including the null terminator) is longer than buflen bytes, an error occurs.

If buf is null, a buffer buflen bytes long is allocated for you with malloc. You can later free the allocated buffer by passing the return value of getcwd to the function free.

Return value

getcwd returns the following values:

□ If buf is not null on input, getcwd returns biif on success, null on error. □ If buf is null on input, getcwd returns a pointer to the allocated buffer.

In the event of an error return, the global variable errno is set to one of the following:

ENODEV No such device

ENOMEMNot enough core

ERANGE Result out of range

See also

Example

#include <stdio.h>
#include <dir.h>
int main(void)
{
   char buffer [MAXPATH];
   getcwd(buffer, MAXPATH);
   printfC'The current directory  is: %s\n", buffer);
   return 0;
}

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.