[MPlayer-dev-eng] [patch 2/5] Dont hardcode filename length

Erik Auerswald auerswal at unix-ag.uni-kl.de
Wed Jan 5 13:59:23 CET 2011


Hi,

On Wed, Jan 05, 2011 at 01:06:59PM +0100, Diego Biurrun wrote:
> On Wed, Jan 05, 2011 at 11:43:51AM +0100, Erik Auerswald wrote:
> > On Tue, Jan 04, 2011 at 09:35:03PM +0100, Tobias Diedrich wrote:
> > > Use limits.h to get the maximum length instead of hardcoding it.
> > > 
> > > -     fname=malloc( 255 );
> > > -     while ( fgets( fname,255,lst_f ) )
> > > +     fname=malloc(PATH_MAX);
> > > +     while ( fgets( fname,PATH_MAX,lst_f ) )
> > 
> > FWIW there is no guarantee that PATH_MAX even exists. See e.g.
> > http://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html or
> > http://www.gnu.org/software/hurd/community/gsoc/project_ideas/maxpath.html or
> > http://bytes.com/topic/c/answers/215365-path_max
> 
> False, POSIX requires it:
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html#tag_13_23_03_02

"A definition of one of the symbolic constants in the following list shall
                                                                     ^^^^^
be omitted from the <limits.h> header on specific implementations where the
^^^^^^^^^^
corresponding value is equal to or greater than the stated minimum, but
where the value can vary depending on the file to which it is applied."

_POSIX_PATH_MAX is required by POSIX. If the value for "PATH_MAX" is variable
and not less than _POSIX_PATH_MAX there it shall not be defined.

> So relying on the existence of PATH_MAX is not a problem.
> Also, it is being used in other places already.

So nobody is using MPlayer on Debian/GNU Hurd. ;-)

All in all I don't see unconditionally using PATH_MAX as an improvement
over 255. For most (relevant) systems both will work fine most of the time.

Erik
-- 
I don't want to see the state of the file when I'm editing.
                        -- Ken Thompson


More information about the MPlayer-dev-eng mailing list