The UNIX standard describes the path name and file name maximum length limit, but its upper limit is too small for the actual application, and Linux increases the limit in its implementation, which is explained in Linux /usr/include/linux/limits.h . , specifically as follows:
1 #ifndef _linux_limits_h2 #define_linux_limits_h3 4 #defineNr_open 10245 6 #defineNgroups_max 65536/* Supplemental Group IDs is available */7 #defineArg_max 131072/* # bytes of args + environ for exec () */8 #defineLink_max 127/* # Links a file may have */9 #defineMax_canon 255/* Size of the canonical input queue */Ten #defineMax_input 255/* Size of the type-ahead buffer */ One #defineName_max 255/* # file name Max characters */ A #definePath_max 4096/* # relative pathname maximum number of characters */ - #definePIPE_BUF 4096/* # bytes in atomic write to a pipe */ - #defineXattr_name_max 255/* # chars in an extended attribute NAME */ the #defineXattr_size_max 65536/* SIZE of an extended attribute value (64k) */ - #defineXattr_list_max 65536/* Size of Extended attribute NameList (64k) */ - - #defineRtsig_max 32 + - #endif
The 11th and 12th lines of the above-mentioned file contents describe the maximum length of the filename and relative path name, respectively. It is necessary to note that the character refers to ASCII characters, and if it is a Chinese character or other language, it is dependent on the encoding.
The above header files can be included in the program and then referenced directly, these values can also be queried using the pathconf () function, and the parameters of the pathconf () function can be found in the table in the article:UNIX Environment Advanced Programming Chapter 2nd UNIX standards and implementation
A simple example demonstration is as follows:
#include <iostream><unistd.h>usingnamespace std; int Main () { << pathconf ("/", _pc_name_max) << Endl; return 0 ;}
Linux path name and file name maximum length limit