_fullpath, _wfullpath

為指定的相對路徑名稱建立絕對路徑或完整路徑名稱。

語法

char *_fullpath(
   char *absPath,
   const char *relPath,
   size_t maxLength
);
wchar_t *_wfullpath(
   wchar_t *absPath,
   const wchar_t *relPath,
   size_t maxLength
);

參數

absPath
包含絕對路徑名稱或完整路徑名稱之緩衝區的指標,或為 NULL

relPath
相對路徑名稱。

maxLength
絕對路徑名稱緩衝區的最大長度 (absPath)。 此長度針對 _fullpath 使用位元組,但針對 wchar_t 使用寬字元 (_wfullpath)。

傳回值

每個函式會傳回包含絕對路徑名稱之緩衝區的指標 (absPath)。 如果發生錯誤(例如,如果傳入 relPath 的值包含無效或找不到的磁碟機號,或建立的絕對路徑名稱長度 absPath 大於 maxLength ),則函式會傳 NULL 回 。

備註

_fullpath 式會將 中的 relPath 相對路徑名稱展開為其完整或絕對路徑,並將這個名稱儲存在 中 absPath 。 如果 absPathNULLmalloc 則用來配置足夠長度的緩衝區來保存路徑名稱。 呼叫者有責任釋放此緩衝區。 相對路徑名稱會從目前位置指定另一個位置的路徑(例如目前的工作目錄: . )。 絕對路徑名稱是相對路徑名稱的擴充狀態,其表示從檔案系統根目錄到達所需位置的完整路徑。 與 不同的 _makepath 是, _fullpath 可用來取得相對路徑的絕對路徑名稱( relPath )包含 ./../ 在其名稱中。

例如,若要使用 C 執行階段常式,應用程式必須包含具有常式宣告的標頭檔。 每個標頭檔 #include 指示詞會以相對方式參考檔案的位置(從應用程式的工作目錄):

#include <stdlib.h>

當檔案的絕對路徑 (實際的檔案系統位置) 可能是:

\\machine\shareName\msvcSrc\crt\headerFiles\stdlib.h

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

_fullpath 會根據目前使用中的多位元組字碼頁,自動將多位元組字元字串引數處理為適當且可辨識的多位元組字元序列。 _wfullpath_fullpath 的寬字元版本;_wfullpath 的字串引數是寬字元字串。 _wfullpath_fullpath 的行為相同,不同之處在于 _wfullpath 不會處理多位元組字元字串。

如果 _DEBUG_CRTDBG_MAP_ALLOC 都已定義,則 對 和 _wfullpath 的呼叫會由 和 _wfullpath_dbg 的呼叫 _fullpath_dbg_fullpath 取代,讓您偵錯記憶體配置。 如需詳細資訊,請參閱 _fullpath_dbg_wfullpath_dbg

如果 maxlen 小於或等於 0,此函式會叫用不正確參數處理常式,如參數驗證 中所述 。 若允許繼續執行,此函式會將 errno 設為 EINVAL,並傳回 NULL

泛型文字常式對應

Tchar.h 常規 _UNICODE and _MBCS 未定義 _MBCS 定義 _UNICODE 定義
_tfullpath _fullpath _fullpath _wfullpath

absPath如果緩衝區為 NULL_fullpath 則呼叫 malloc 以配置緩衝區並忽略 maxLength 引數。 呼叫者有責任適當地解除配置此緩衝區(使用 free )。 如果 relPath 引數指定磁碟機,此磁碟機的目前目錄會與路徑合併。

需求

函式 必要的標頭
_fullpath <stdlib.h>
_wfullpath <stdlib.h><wchar.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_fullpath.c
// This program demonstrates how _fullpath
// creates a full path from a partial path.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>

void PrintFullPath( char * partialPath )
{
   char full[_MAX_PATH];
   if( _fullpath( full, partialPath, _MAX_PATH ) != NULL )
      printf( "Full path is: %s\n", full );
   else
      printf( "Invalid path\n" );
}

int main( void )
{
   PrintFullPath( "test" );
   PrintFullPath( "\\test" );
   PrintFullPath( "..\\test" );
}
Full path is: C:\Documents and Settings\user\My Documents\test
Full path is: C:\test
Full path is: C:\Documents and Settings\user\test

另請參閱

檔案處理
_getcwd, _wgetcwd
_getdcwd, _wgetdcwd
_makepath, _wmakepath
_splitpath, _wsplitpath