max_path

MAX_PATH是C語言運行時庫中通過#define指令定義的一個宏常量,它定義了編譯器所支持的最長全路徑名的長度。

基本介紹

  • 中文名:max_path
  • 來源:C++函式館
  • 類型:定義頭檔案
  • 作用:最大化
簡介,相關信息,

簡介

在VC++6.0中, _MAX_PATH的值為260。
所屬庫:stdlib.h
在Windows SDK中,還有一個預定義常量MAX_PATH,和這個常量是一樣的。
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <errno.h>typedef struct _stat StatusInfo;#define __STR(const_num) # const_num#define STR(const_num) __STR(const_num)int main(void){    char filename[_MAX_PATH] = { '\0' };    StatusInfo buf;    StatusInfo *pbuf = &buf;    fputs("Please input file name >>> ", stdout);    scanf("%"STR(_MAX_PATH)"s", filename);    if ( _stat(filename, &buf) != 0 )    {        switch (errno)        {        case ENOENT:            fprintf(stderr, "Error: File %s not found.\n", filename);            break;        case EINVAL:            fprintf(stderr, "Error: Invalid parameter to _stat.\n");            break;        default:            fprintf(stderr, "Error: Unexpected error in _stat.\n");            break;        }        return EXIT_FAILURE;    }    else    {        printf("File size : %ld bytes\n", pbuf->st_size);        printf("Drive : %c:\n", pbuf->st_dev + 'A');        printf("Time modified: %s\n", ctime(&pbuf->st_mtime));        return EXIT_SUCCESS;    }}

相關信息

在delphi中的Windows單元也定義了一個同樣意義的常量,該常量代表 Windows 允許路徑的最大長度。這樣系統性的約定好長度,就不會造成不必要的麻煩。定義方式如下代碼所示:
unit Windows;{$ALIGN ON}{$MINENUMSIZE 4}{$WEAKPACKAGEUNIT}{$IFDEF LINUX}{$DEFINE LINUXCRITSECTION}{$ENDIF}interfaceuses Types{$IFDEF LINUX}, Libc {$ENDIF};(*$HPPEMIT '// WINVER check BEGIN ' *)(*$HPPEMIT '#if (WINVER < 0x0400)' *)(*$HPPEMIT '#error WINVER < 0x0400' *)(*$HPPEMIT '#endif' *)(*$HPPEMIT '// WINVER check END. ' *)(*$HPPEMIT '' *)(*$HPPEMIT '// WIN2K SDK fixes BEGIN ' *)(*$HPPEMIT '#ifndef WINTRUST_H' *)(*$HPPEMIT '#include<wintrust.h>' *)(*$HPPEMIT '#endif' *)(*$HPPEMIT '// WIN2K SDK fixes END. ' *)(*$HPPEMIT '//' *)(*$HPPEMIT '// WINDOWS provides two definitions of BLOB: wtypes.h defines a' *)(*$HPPEMIT '// BLOB as a tagBLOB struct whereas nspapi.h defines a BLOB as a _BLOB' *)(*$HPPEMIT '// struct. Unfortunately, VCL does not use the portable BLOB type but' *)(*$HPPEMIT '// rather relies on tagBLOB. So here we use a kludge to try to determine' *)(*$HPPEMIT '// which flavour of BLOB we have (which is determined by the order of header' *)(*$HPPEMIT '// inclusion by the compilation unit). If it is the _BLOB, we expose the' *)(*$HPPEMIT '// tagBLOB type for VCL.' *)(*$HPPEMIT '//' *)(*$HPPEMIT '#if sizeof(_BLOB) == 8 // We know that BLOB is 8 bytes ' *)(*$HPPEMIT 'typedef _BLOB tagBLOB; // If unknown, _BLOB would be 4 ' *)(*$HPPEMIT '#endif // tagBLOB Kludge' *)(*$HPPEMIT '#if sizeof(tagBLOB) == 4 // tagBLOB has probably not been defined yet' *)(*$HPPEMIT '#ifndef _tagBLOB_DEFINED' *)(*$HPPEMIT '#define _tagBLOB_DEFINED' *)(*$HPPEMIT '#define _BLOB_DEFINED' *)(*$HPPEMIT '#define _LPBLOB_DEFINED' *)(*$HPPEMIT 'typedef struct tagBLOB' *)(*$HPPEMIT ' {' *)(*$HPPEMIT ' ULONG cbSize;' *)(*$HPPEMIT ' /* [size_is] */ BYTE __RPC_FAR *pBlobData;' *)(*$HPPEMIT ' } BLOB;' *)(*$HPPEMIT '' *)(*$HPPEMIT 'typedef struct tagBLOB __RPC_FAR *LPBLOB;' *)(*$HPPEMIT '#endif // _tagBLOB_DEFINED' *)(*$HPPEMIT '#endif // sizeof(tagBLOB) == 4' *)(*$HPPEMIT '' *)(*$HPPEMIT '#if defined(WIN32_LEAN_AND_MEAN) && !defined(_DDEHEADER_INCLUDED_)' *)(*$HPPEMIT '#include <dde.h>' *)(*$HPPEMIT '#endif // WIN32_LEAN_AND_MEAN & _DDEHEADER_INCLUDED_' *)(*$HPPEMIT '' *)(*$HPPEMIT 'namespace Windows {'*)(*$HPPEMIT 'typedef _LARGE_INTEGER TLargeInteger;'*)(*$HPPEMIT ''*)(*$HPPEMIT '#if (WINVER >= 0x0500)'*)(*$HPPEMIT 'typedef BITMAPV5HEADER *PBitmapV5Header;'*)(*$HPPEMIT 'typedef BITMAPV5HEADER TBitmapV5Header;'*)(*$HPPEMIT 'typedef tagEMRGRADIENTFILL *PEMGradientFill;'*)(*$HPPEMIT 'typedef tagEMRGRADIENTFILL TEMGradientFill;'*)(*$HPPEMIT 'typedef tagEMRALPHABLEND *PEMRAlphaBlend;'*)(*$HPPEMIT 'typedef tagEMRALPHABLEND TEMRAlphaBlend;'*)(*$HPPEMIT 'typedef tagEMRTRANSPARENTBLT *PEMRTransparentBLT;'*)(*$HPPEMIT 'typedef tagEMRTRANSPARENTBLT TEMRTransparentBLT;'*)(*$HPPEMIT 'typedef _WGLSWAP *PWGLSwap;'*)(*$HPPEMIT 'typedef _WGLSWAP TWGLSwap;'*)(*$HPPEMIT 'typedef tagMOUSEMOVEPOINT *PMouseMovePoint;'*)(*$HPPEMIT 'typedef tagMOUSEMOVEPOINT TMouseMovePoint;'*)(*$HPPEMIT 'typedef FLASHWINFO TFlashWInfo;'*)(*$HPPEMIT 'typedef tagMENUINFO *PMenuInfo;'*)(*$HPPEMIT 'typedef tagMENUINFO TMenuInfo;'*)(*$HPPEMIT 'typedef tagMENUGETOBJECTINFO *PMenuGetObjectInfo;'*)(*$HPPEMIT 'typedef tagMENUGETOBJECTINFO TMenuGetObjectInfo;'*)(*$HPPEMIT 'typedef tagGUITHREADINFO *PGUIThreadInfo;'*)(*$HPPEMIT 'typedef tagGUITHREADINFO TGUIThreadInfo;'*)(*$HPPEMIT 'typedef tagCURSORINFO *PCursorInfo;'*)(*$HPPEMIT 'typedef tagCURSORINFO TCursorInfo;'*)(*$HPPEMIT 'typedef tagWINDOWINFO *PWindowInfo;'*)(*$HPPEMIT 'typedef tagWINDOWINFO TWindowInfo;'*)(*$HPPEMIT 'typedef tagTITLEBARINFO *PTitleBarInfo;'*)(*$HPPEMIT 'typedef tagTITLEBARINFO TTitleBarInfo;'*)(*$HPPEMIT 'typedef tagMENUBARINFO *PMenuBarInfo;'*)(*$HPPEMIT 'typedef tagMENUBARINFO TMenuBarInfo;'*)(*$HPPEMIT 'typedef tagSCROLLBARINFO *PScrollBarInfo;'*)(*$HPPEMIT 'typedef tagSCROLLBARINFO TScrollBarInfo;'*)(*$HPPEMIT 'typedef tagCOMBOBOXINFO *PComboBoxInfo;'*)(*$HPPEMIT 'typedef tagCOMBOBOXINFO TComboBoxInfo;'*)(*$HPPEMIT 'typedef tagALTTABINFO *PAltTabInfo;'*)(*$HPPEMIT 'typedef tagALTTABINFO TAltTabInfo;'*)(*$HPPEMIT '#endif'*)(*$HPPEMIT ''*)(*$HPPEMIT '} // namespace Windows'*)(*$HPPEMIT ''*)type{ Translated from WINDEF.H }WCHAR = WideChar;{$EXTERNALSYM WCHAR}PWChar = PWideChar;LPSTR = PAnsiChar;{$EXTERNALSYM LPSTR}PLPSTR = ^LPSTR;{$EXTERNALSYM PLPSTR}LPCSTR = PAnsiChar;{$EXTERNALSYM LPCSTR}LPCTSTR = PAnsiChar;{$EXTERNALSYM LPCTSTR}LPTSTR = PAnsiChar;{$EXTERNALSYM LPTSTR}LPWSTR = PWideChar;{$EXTERNALSYM LPWSTR}PLPWSTR = ^LPWSTR;{$EXTERNALSYM PLPWSTR}LPCWSTR = PWideChar;{$EXTERNALSYM LPCWSTR}DWORD = Types.DWORD;{$EXTERNALSYM DWORD}BOOL = LongBool;{$EXTERNALSYM BOOL}PBOOL = ^BOOL;{$EXTERNALSYM PBOOL}PByte = Types.PByte;PINT = ^Integer;{$EXTERNALSYM PINT}PSingle = ^Single;PWORD = ^Word;{$EXTERNALSYM PWORD}PDWORD = ^DWORD;{$EXTERNALSYM PDWORD}LPDWORD = PDWORD;{$EXTERNALSYM LPDWORD}UCHAR = Byte;{$EXTERNALSYM UCHAR}PUCHAR = ^Byte;{$EXTERNALSYM PUCHAR}SHORT = Smallint;{$EXTERNALSYM SHORT}UINT = LongWord;{$EXTERNALSYM UINT}PUINT = ^UINT;{$EXTERNALSYM PUINT}ULONG = Cardinal;{$EXTERNALSYM ULONG}PULONG = ^ULONG;{$EXTERNALSYM PULONG}PLongint = System.PLongint;{$EXTERNALSYM PLongint}PInteger = System.PInteger;{$EXTERNALSYM PInteger}PLongWord = System.PLongWord;{$EXTERNALSYM PLongWord}PSmallInt = System.PSmallInt;{$EXTERNALSYM PSmallInt}PDouble = System.PDouble;{$EXTERNALSYM PDouble}PShortInt = System.PShortInt;{$EXTERNALSYM PShortInt}LCID = DWORD;{$EXTERNALSYM LCID}LANGID = Word;{$EXTERNALSYM LANGID}THandle = System.THandle;PHandle = ^THandle;// From BaseTsd.hINT_PTR = Integer;{$EXTERNALSYM INT_PTR}LONG_PTR = Integer;{$EXTERNALSYM LONG_PTR}UINT_PTR = Cardinal;{$EXTERNALSYM UINT_PTR}ULONG_PTR = Cardinal;{$EXTERNALSYM ULONG_PTR}DWORD_PTR = ULONG_PTR;{$EXTERNALSYM DWORD_PTR}constMAX_PATH = 260;{$EXTERNALSYM MAX_PATH}

相關詞條

熱門詞條

聯絡我們