_getdcwd -- Get Full Path Name of Current Directory

Format

#include <direct.h>
char *_getdcwd(int drive, char *pathbuf, int n);

Language Level: Extension
_getdcwd gets the full path name for the current directory of the specified drive, and stores it in the location pointed to by pathbuf. The drive argument is an integer value representing the drive (A: is 1, B: is 2, and so on).

The integer argument n specifies the maximum length for the path name. An error occurs if the length of the path name, including the terminating null character, exceeds n characters.

If the pathbuf argument is NULL, _getdcwd uses malloc to reserve a buffer of at least n bytes to store the path name. If the current working directory string is more than n bytes, a large enough buffer will be allocated to contain the string. You can later free this buffer using the _getdcwd return value as the argument to free.

The alternatives to this function, on OS/2, are the DosQueryCurrentDir and DosQueryCurrentDisk API calls.

The alternative to this function, on Windows, is the GetCurrentDirectory API call.

Return Value
_getdcwd returns pathbuf. If an error occurs, _getdcwd returns NULL and sets errno to one of the following values:

Value Meaning
ENOMEM Not enough storage space available to reserve n bytes (when pathbuf is NULL).
ERANGE The path name is longer than n characters.
EOS2ERR A system call failed. Use _doserrno to obtain more information about the return code.

Example
This example uses _getdcwd to obtain the current working directory of drive C.

#include <stdio.h>
#include <direct.h>
#include <errno.h>
#define C_DRIVE 3
int main(void)
{
   char *retBuffer;
   retBuffer = _getdcwd(C_DRIVE, NULL, 0);
   if (NULL == retBuffer)
      printf("An error has occurred, errno is set to %d.\n", errno);
   else
      printf("%s is the current working directory in drive C.\n", retBuffer);
   return 0;
   /************************************************************************
      The output should be similar to:
      C:\ is the current working directory in drive C.
   ************************************************************************/
}



chdir -- Change Current Working Directory
_chdrive -- Change Current Working Drive
_fullpath -- Get Full Path Name of Partial Path
_getcwd -- Get Path Name of Current Directory
_getdrive -- Get Current Working Drive
malloc -- Reserve Storage Block
<direct.h>