Using C, how do we find the max size of char* allowed by a file system?
+1
A:
My assumption here is that you are asking for "What is the maximum allowable length of a file name allowed by a file system?"
This is dependent on the OS and how the filesystem is implemented, but most systems have defined macros that can be referenced.
In Linux, limits.h
, the value can be reference by the macro PATH_MAX
, 4096 (Current as of kernel 2.6.35)
In Windows, WinDef.h
, the value can be reference by the macro MAX_PATH
, 260 (Current as of Windows 7). This does not include the use of UNC paths (See comment below).
linuxuser27
2010-09-16 00:46:24
In Windows, the story is much more complex as UNC paths have a separate (and much larger) maximum length. The type file system to which the path points matters too. See http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx for a bunch of gory details.
RBerteig
2010-09-16 00:55:22
+1 Good point. Updated solution to mention.
linuxuser27
2010-09-16 01:04:44
I think a completely portable solution that uses only the C library would have to rely on FILENAME_MAX (from `stdio.h`).
Dan Moulding
2010-09-16 01:48:31