Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MAXNAMELEN vs MAXNAMLEN

133 views
Skip to first unread message

Rich Teer

unread,
Jan 23, 2004, 1:46:43 AM1/23/04
to
Hi all,

I have a reconcilliation type of question. <sys/param.h>
says this:

/*
* MAXPATHLEN defines the longest permissible path length,
* including the terminating null, after expanding symbolic links.
* MAXNAMELEN is the length (including the terminating null) of
* the longest permissible file (component) name.
*/
#define MAXPATHLEN 1024
#define MAXNAMELEN 256


Whereas <dirent.h> says this:

#define MAXNAMLEN 512 /* maximum filename length */


So, one header file claims that the maximum length of
a file name (i.e., pathname component) is 256 characters,
and another claims that it is 512.

Shouldn't these two values be the same? I mean, how can
a UFS file system support 512 character file names when
the system itself is restricted to 256? (Or am I missing
something here?)

TIA,

--
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net

Casper H.S. Dik

unread,
Jan 23, 2004, 4:22:53 AM1/23/04
to
Rich Teer <rich...@rite-group.com> writes:

>Whereas <dirent.h> says this:

>#define MAXNAMLEN 512 /* maximum filename length */

That seems to be internal to the library readdir implementation;
still looks wrong, though.

>So, one header file claims that the maximum length of
>a file name (i.e., pathname component) is 256 characters,
>and another claims that it is 512.

>Shouldn't these two values be the same? I mean, how can
>a UFS file system support 512 character file names when
>the system itself is restricted to 256? (Or am I missing
>something here?)

The actual supported maximum length is filesystem dependent and
should be inquired using pathconf(file, _PC_NAME_MAX)


Casper

lvi...@yahoo.com

unread,
Jan 27, 2004, 8:48:29 AM1/27/04
to

According to Rich Teer <rich...@rite-group.com>:
: <sys/param.h>
:says this:
:
:#define MAXNAMELEN 256

:
:Whereas <dirent.h> says this:
:
:#define MAXNAMLEN 512 /* maximum filename length */
:

In case someone is interested, dirent.h says this:

#if defined(__EXTENSIONS__) || \
(!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE))

#define MAXNAMLEN 512 /* maximum filename length */

So dirent.h is defining info for an extension or for code which
does not have POSIX_C_SOURCE or _XOPEN_SOURCE defined.

Since in most cases, these defines are not going to be present,
including the two header files will most often attempt to define
the same symbol with two different values...

Seems like a problem to me...
--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvi...@yahoo.com > <URL: http://www.purl.org/NET/lvirden/ >

Rich Teer

unread,
Jan 27, 2004, 11:45:48 AM1/27/04
to
On Tue, 27 Jan 2004 lvi...@yahoo.com wrote:

> In case someone is interested, dirent.h says this:
>
> #if defined(__EXTENSIONS__) || \
> (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE))
>
> #define MAXNAMLEN 512 /* maximum filename length */
>
>
> So dirent.h is defining info for an extension or for code which
> does not have POSIX_C_SOURCE or _XOPEN_SOURCE defined.

Yep.

> Since in most cases, these defines are not going to be present,
> including the two header files will most often attempt to define
> the same symbol with two different values...

Nope. MAXNAMLEN and MAXNAMELEN are two different symbols,
not two the same with a typo! :-)

Fortunately, I've received email from Sun engineers resolving
this discrepancy.

Frank Cusack

unread,
Jan 28, 2004, 6:06:47 AM1/28/04
to
On Tue, 27 Jan 2004 16:45:48 GMT Rich Teer <rich...@rite-group.com> wrote:
> Fortunately, I've received email from Sun engineers resolving
> this discrepancy.

Fortunately for you, not for us! Spill it.

/fc

Rich Teer

unread,
Jan 28, 2004, 1:00:52 PM1/28/04
to

My mistake: I didn't receive an email. I was thinking of
Casper's posting a few days ago (it's on groups.google.com).

Here's the gist of what he said:

That seems to be internal to the library readdir implementation;
still looks wrong, though.

The actual supported maximum length is filesystem dependent and
should be inquired using pathconf(file, _PC_NAME_MAX).

HTH,

0 new messages