Редактиране

Споделяне чрез


_getdcwd, _wgetdcwd

Gets the full path of the current working directory on the specified drive.

Syntax

char *_getdcwd(
   int drive,
   char *buffer,
   int maxlen
);
wchar_t *_wgetdcwd(
   int drive,
   wchar_t *buffer,
   int maxlen
);

Parameters

drive
A non-negative integer that specifies the drive (0 = default drive, 1 = A, 2 = B, and so on).

If the specified drive isn't available, the invalid parameter handler is invoked. It's also invoked when the kind of drive (for example, removable, fixed, CD-ROM, RAM disk, or network drive) can't be determined. For more information, see Parameter validation.

buffer
Storage location for the path, or NULL.

If NULL is specified, this function allocates a buffer of at least maxlen size by using malloc, and the return value of _getdcwd is a pointer to the allocated buffer. The buffer can be freed by calling free and passing it the pointer.

maxlen
A nonzero positive integer that specifies the maximum length of the path, in characters: char for _getdcwd and wchar_t for _wgetdcwd.

If maxlen is less than or equal to zero, the invalid-parameter handler is invoked. For more information, see Parameter validation.

Return value

Pointer to a string that represents the full path of the current working directory on the specified drive, or NULL, which indicates an error.

If buffer is specified as NULL and there's insufficient memory to allocate maxlen characters, an error occurs and errno is set to ENOMEM. If the length of the path including the terminating null character exceeds maxlen, an error occurs, and errno is set to ERANGE. For more information about these error codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.

Remarks

The _getdcwd function gets the full path of the current working directory on the specified drive and stores it at buffer. If the current working directory is set to the root, the string ends with a backslash (\). If the current working directory is set to a directory other than the root, the string ends with the name of the directory and not with a backslash.

_wgetdcwd is a wide-character version of _getdcwd, and its buffer parameter and return value are wide-character strings. Otherwise, _wgetdcwd and _getdcwd behave identically.

This function is thread-safe even though it depends on GetFullPathName, which is itself not thread-safe. However, you can violate thread safety if your multithreaded application calls both this function and GetFullPathName.

The version of this function that has the _nolock suffix behaves identically to this function except that it isn't thread-safe and isn't protected from interference by other threads. For more information, see _getdcwd_nolock, _wgetdcwd_nolock.

When _DEBUG and _CRTDBG_MAP_ALLOC are defined, calls to _getdcwd and _wgetdcwd are replaced by calls to _getdcwd_dbg and _wgetdcwd_dbg, so that you can debug memory allocations. For more information, see_getdcwd_dbg, _wgetdcwd_dbg.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Generic-text routine mappings

Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined
_tgetdcwd _getdcwd _getdcwd _wgetdcwd

Requirements

Routine Required header
_getdcwd <direct.h>
_wgetdcwd <direct.h> or <wchar.h>

For more compatibility information, see Compatibility.

Example

See the example in _getdrive.

See also

Directory control
_chdir, _wchdir
_getcwd, _wgetcwd
_getdrive
_mkdir, _wmkdir
_rmdir, _wrmdir