What are the proper uses of MAXNAMLEN, NAME_MAX, and FILENAME_MAX?
Do they represent filenames with or without paths?  Do they include
the terminating null or not?  The source seems inconsistent:

[EMAIL PROTECTED]/usr/src] egrep -R '(MAXNAMLEN|NAME_MAX) ?\+ ?1' .
./bin/csh/file.c:    Char    name[MAXNAMLEN + 1], extended_name[MAXNAMLEN + 1];
./games/hunt/huntd/conf.c:      char nm[MAXNAMLEN + 1];
./gnu/egcs/gcc/config/winnt/dirent.h:    char   d_name[MAXNAMLEN + 1];
./gnu/usr.bin/cvs/contrib/dirfns.shar:X char    d_name[MAXNAMLEN + 1];  /* name 
must be no longer than this */
./gnu/usr.bin/cvs/contrib/dirfns.shar:X char    d_name[MAXNAMLEN + 1];  /* name 
must be no longer than this */
./gnu/usr.bin/cvs/contrib/dirfns.shar:X    ((sizeof (struct direct) - 
(MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
./gnu/usr.bin/cvs/vms/ndir.h:   char            d_name[MAXNAMLEN+1];    /* name 
of file */
./gnu/usr.bin/cvs/windows-NT/ndir.h:  char d_name[MAXNAMLEN + 1];       /* 
garentee null termination */
./gnu/usr.bin/gcc/gcc/config/i386/xm-djgpp.h:      static char 
fixed_path[FILENAME_MAX + 1];    \
./gnu/usr.bin/lynx/WWW/Library/Implementation/HTVMSUtils.c:     char            
d_name[255+1];  /* name (up to MAXNAMLEN + 1) */
./gnu/usr.bin/lynx/WWW/Library/Implementation/HTVMSUtils.c: * at least 
MAXNAMLEN + 1 (more may be added for padding).
./gnu/usr.bin/lynx/WWW/Library/Implementation/HTVMSUtils.c:     
(((sizeof(struct dirent) - (MAXNAMLEN+1) + ((dp)->d_namlen+1)) +3) & ~3)
./gnu/usr.bin/perl/doio.c:                char newname[FILENAME_MAX+1];
./lib/csu/common.h:char                 __progname_storage[NAME_MAX+1];
./lib/csu/alpha/crt0.c:char     __progname_storage[NAME_MAX+1];
./lib/csu/amd64/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/arm/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/hppa/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/i386/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/powerpc/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/sparc/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/csu/sparc64/crt0.c:char   __progname_storage[NAME_MAX+1];
./lib/csu/hppa64/crt0.c:char __progname_storage[NAME_MAX+1];
./lib/libc/gen/authenticate.c:  char namebuf[MAXLOGNAME + 1 + NAME_MAX + 1];
./lib/libc/gen/authenticate.c:  char namebuf[MAXLOGNAME + 1 + NAME_MAX + 1];
./lib/libc/gen/getcwd.c:                if (bup + 3  + MAXNAMLEN + 1 >= eup) {
./lib/libc/sys/getdirentries.2:char     d_name[MAXNAMLEN + 1]; /* see below */
./lib/libc/sys/.#getdirentries.2.1.19:char      d_name[MAXNAMLEN + 1]; /* see 
below */
./lib/libc/time/localtime.c:                            (2 * (MY_TZNAME_MAX + 
1)))];
./lib/libssl/src/crypto/dso/dso_vms.c:  char filename[FILENAME_MAX+1];
./lib/libssl/src/crypto/dso/dso_vms.c:  char imagename[FILENAME_MAX+1];
./sbin/newfs/mkfs.c:    u_char  d_name[MAXNAMLEN + 1];
./share/man/man5/dir.5: char    d_name[MAXNAMLEN + 1];  /* maximum name length 
*/
./sys/compat/ibcs2/ibcs2_dirent.h:      char            d_name[IBCS2_MAXNAMLEN 
+ 1];
./sys/compat/linux/linux_dirent.h:      char            d_name[LINUX_MAXNAMLEN 
+ 1];
./sys/compat/linux/linux_dirent.h:      char            d_name[LINUX_MAXNAMLEN 
+ 1];
./sys/compat/linux/linux_getcwd.c:#define DIRENT_MINSIZE (sizeof(struct dirent) 
- (LINUX_MAXNAMLEN+1) + 4)
./sys/compat/netbsd/netbsd_getcwd.c:#define DIRENT_MINSIZE (sizeof(struct 
dirent) - (MAXNAMLEN+1) + 4)
./sys/compat/sunos/sunos_dirent.h:      char            d_name[SUNOS_MAXNAMLEN 
+ 1];
./sys/compat/svr4/svr4_dirent.h:        char            d_name[SVR4_MAXNAMLEN + 
1];
./sys/compat/svr4/svr4_dirent.h:        char            d_name[SVR4_MAXNAMLEN + 
1];
./sys/isofs/udf/udf_vnops.c:    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + 
(((dp)->d_namlen+1 + 3) &~ 3))
./sys/nfs/nfs_vnops.c:#define   NFS_DIRHDSIZ    (sizeof (struct nfs_dirent) - 
(MAXNAMLEN + 1))
./sys/stand/ls.c:                       if (((DP *)dp)->d_namlen > MAXNAMLEN+1) 
{
./sys/sys/dir.h:    ((sizeof (struct direct) - (MAXNAMLEN+1)) + 
(((dp)->d_namlen+1 + 3) &~ 3))
./sys/sys/dirent.h:     char    d_name[MAXNAMLEN + 1];  /* name must be no 
longer than this */
./sys/sys/dirent.h:    ((sizeof (struct dirent) - (MAXNAMLEN+1)) + 
(((dp)->d_namlen+1 + 3) &~ 3))
./sys/ufs/ufs/dir.h:    char      d_name[MAXNAMLEN + 1];/* name with length <= 
MAXNAMLEN */
./sys/ufs/ufs/dir.h:    ((sizeof(struct direct) - (MAXNAMLEN+1)) + 
(((dp)->d_type+1 + 3) &~ 3)) : \
./sys/ufs/ufs/dir.h:    ((sizeof(struct direct) - (MAXNAMLEN+1)) + 
(((dp)->d_namlen+1 + 3) &~ 3)))
./sys/ufs/ufs/dir.h:    ((sizeof(struct direct) - (MAXNAMLEN+1)) + 
(((dp)->d_namlen+1 + 3) &~ 3))
./sys/ufs/ufs/dirhash.h:#define DH_NFSTATS      (DIRECTSIZ(MAXNAMLEN + 1) / 
DIRALIGN)
./sys/xfs/xfs_node-bsd.c:    char name[MAXNAMLEN + 1];
./usr.bin/ar/archive.h: char name[MAXNAMLEN + 1];       /* name */
./usr.bin/ctags/tree.c: char    nbuf[1+MAXNAMLEN+1];
./usr.bin/less/lsystem.c:       char cwd[FILENAME_MAX+1];
./usr.bin/patch/patch.c:static char     rejname[NAME_MAX + 1];
./usr.sbin/afs/src/nnpfs/bsd/nnpfs_node-bsd.c:    char name[MAXNAMLEN + 1];
./usr.sbin/cron/database.c:             char fname[MAXNAMLEN+1], 
tabname[MAXNAMLEN];
./usr.sbin/dev_mkdb/dev_mkdb.c: u_char buf[MAXNAMLEN + 1];
./usr.sbin/lpr/common_source/lp.h:      char    q_name[MAXNAMLEN+1];    /* 
control file name */
./usr.sbin/syslogd/syslogd.c:   char prog[NAME_MAX+1];
./usr.sbin/syslogd/syslogd.c:   char cline[LINE_MAX], prog[NAME_MAX+1], *p;
[EMAIL PROTECTED]/usr/src] egrep -R '(MAXNAMLEN|NAME_MAX)\]' .
./gnu/usr.bin/binutils/gas/config/tc-tic4x.c:    char name[TIC4X_NAME_MAX];     
/* Mnemonic of instruction.  */
./gnu/usr.bin/binutils/gdb/go32-nat.c:static char child_cwd[FILENAME_MAX];
./gnu/usr.bin/binutils/ld/ldgram.y:static char *error_names[ERROR_NAME_MAX];
./gnu/usr.bin/cvs/emx/filesubr.c:    char fn1[MAXNAMLEN], fn2[MAXNAMLEN];
./gnu/usr.sbin/mkhybrid/src/files.c:  de->d_name[NAME_MAX]=0;
./gnu/usr.sbin/sendmail/sendmail/arpadate.c:    static char b[43 + TZNAME_MAX];
./lib/libc/gen/ttyname.c:static char buf[TTY_NAME_MAX];
./lib/libc/time/localtime.c:            char            fullname[FILENAME_MAX];
./lib/libc/time/strftime.c:     char                    filename[FILENAME_MAX];
./lib/libutil/uucplock.c:       char lckname[sizeof(_PATH_UUCPLOCK) + 
MAXNAMLEN],
./lib/libutil/uucplock.c:            lcktmpname[sizeof(_PATH_UUCPLOCK) + 
MAXNAMLEN];
./lib/libutil/uucplock.c:       char lckname[sizeof(_PATH_UUCPLOCK) + 
MAXNAMLEN];
./lib/libutil/uucplock.c:       char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN];
./sbin/fsck_ext2fs/utilities.c:         if (cp < &namebuf[EXT2FS_MAXNAMLEN])
./sbin/fsck_ffs/utilities.c:            if (cp < &namebuf[MAXNAMLEN])
./sbin/isakmpd/ike_auth.c:      char            filename[FILENAME_MAX];
./sys/isofs/cd9660/cd9660_lookup.c:     char altname[NAME_MAX];
./sys/ufs/ext2fs/ext2fs_dir.h:  char      e2d_name[EXT2FS_MAXNAMLEN];/* name 
with length <= EXT2FS_MAXNAMLEN */
./usr.bin/mg/fileio.c:  char             user[LOGIN_NAME_MAX], path[MAXPATHLEN];
./usr.bin/mixerctl/mixerctl.c:  char name[FIELD_NAME_MAX];
./usr.bin/mixerctl/mixerctl.c:  char tmp[FIELD_NAME_MAX];
./usr.bin/tip/uucplock.c:       char tbuf[sizeof(_PATH_LOCKDIRNAME) + 
MAXNAMLEN];
./usr.bin/tip/uucplock.c:       char tbuf[sizeof(_PATH_LOCKDIRNAME) + 
MAXNAMLEN];
./usr.bin/tip/value.c:  char file[FILENAME_MAX];
./usr.bin/wall/ttymsg.c:        static char device[MAXNAMLEN] = _PATH_DEV;
./usr.bin/cvs/file.c:   char                            ip_pat[MAXNAMLEN];
./usr.bin/cvs/file.c:   char path[MAXPATHLEN], buf[MAXNAMLEN];
./usr.bin/cvs/resp.c:   char newname[MAXNAMLEN], *file;
./usr.bin/cvs/status.c: char buf[MAXNAMLEN], fpath[MAXPATHLEN], 
rcspath[MAXPATHLEN];
./usr.sbin/cron/database.c:             char fname[MAXNAMLEN+1], 
tabname[MAXNAMLEN];
./usr.sbin/lpr/common_source/displayq.c:static char     current[NAME_MAX]; /* 
current file being printed */
./usr.sbin/lpr/common_source/displayq.c:static char     file[NAME_MAX]; /* 
print file name */
./usr.sbin/lpr/common_source/rmjob.c:static char        current[NAME_MAX];      
/* active control file name */
./usr.sbin/lpr/lpd/printjob.c:static char       jobname[NAME_MAX];      /* job 
or file name */
./usr.sbin/lpr/lpd/recvjob.c:static char         dfname[NAME_MAX];      /* data 
files */
./usr.sbin/lpr/lpd/recvjob.c:static char         tfname[NAME_MAX];      /* tmp 
copy of cf before linking */
./usr.sbin/mopd/mopd/process.c: char            filename[FILENAME_MAX];
./usr.sbin/syslogd/ttymsg.c:    static char device[MAXNAMLEN] = _PATH_DEV;
./plusone.grep:./usr.sbin/cron/database.c:              char 
fname[MAXNAMLEN+1], tabname[MAXNAMLEN];

chdir(2) says:

     [ENAMETOOLONG]
                   A component of a pathname exceeded {NAME_MAX} characters,
                   or an entire path name exceeded {PATH_MAX} characters.

dir(5) says:

     /*
      * A directory entry has a struct dirent at the front of it, containing
      * its inode number, the length of the entry, and the length of the name
      * contained in the entry.  These are followed by the name padded to a 4
      * byte boundary with null bytes.  All names are guaranteed NUL terminated.
      * The maximum length of a name in a directory is MAXNAMLEN.
      */

     struct dirent {
             u_int32_t       d_fileno;       /* file number of entry */
             u_int16_t       d_reclen;       /* length of this record */
             u_int8_t        d_type;         /* file type, see below */
             u_int8_t        d_namlen;       /* length of string in d_name */
     #define MAXNAMLEN       255
             char    d_name[MAXNAMLEN + 1];  /* maximum name length */
     };

Can someone clarify?  Thank you.

-Ray-

Reply via email to