delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/01/13/10:38:37

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <3E22D46D.116FDB95@phekda.freeserve.co.uk>
Date: Mon, 13 Jan 2003 14:59:57 +0000
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: DJGPP workers <djgpp-workers AT delorie DOT com>
Subject: FILENAME_MAX - does it include a nul terminator?
Reply-To: djgpp-workers AT delorie DOT com

Hello.

I've just been looking at the symlink code, which uses FILENAME_MAX. And I
wonder if FILENAME_MAX includes the nul terminator. C99 says this about
FILENAME_MAX:

"FILENAME_MAX which expands to an integer constant expression that is the size
needed for an array of char large enough to hold the longest file name string
that the implementation guarantees can be opened;"

So it seems that FILENAME_MAX does include the nul terminator. (PATH_MAX does
too.)

There checks for there being enough buffer space:

    if (strlen(foo) > FILENAME_MAX)
        do_something;
    else
        return(an_error).

Surely the test should be >= FILENAME_MAX?

PATH_MAX also includes space for the terminator. I haven't looked at uses of
that, but I suspect a similar problem may exist.

Bye, Rich =]

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019