bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #55449] [PATCH] Use FILENAME_MAX in maxfilename.cpp


From: Steffen Nurpmeso
Subject: Re: [bug #55449] [PATCH] Use FILENAME_MAX in maxfilename.cpp
Date: Thu, 22 Oct 2020 01:31:55 +0200
User-agent: s-nail v14.9.19

Ingo Schwarze wrote in
 <20201021231159.GE12500@athene.usta.de>:
 ...
 |Now, arguably, if pathconf(3) fails, which can easily happen if the
 |input argument is garbage, the function should not return (size_t)-1,
 |which is a large value.
 ...
 |Anyone willing to fix this particular bug?

I have this (preliminary) in s-roff:

  /* POSIX 2008/Cor 1-2013 defines a minimum of 14 for _POSIX_NAME_MAX */
  #ifndef NAME_MAX
  # ifdef _POSIX_NAME_MAX
  #  define NAME_MAX _POSIX_NAME_MAX
  # else
  #  define NAME_MAX 14
  # endif
  #endif
  #if NAME_MAX + 0 < 8
  # error NAME_MAX is too small
  #endif
  
  /* POSIX 2008/Cor 1-2013 defines for
   * - _POSIX_PATH_MAX a minimum of 256
   * - _XOPEN_PATH_MAX a minimum of 1024
   * NFS RFC 1094 from March 1989 defines a MAXPATHLEN of 1024, so we really
   * should avoid anything smaller than that! */
  #ifndef PATH_MAX
  # ifdef MAXPATHLEN
  #  define PATH_MAX MAXPATHLEN
  # else
  #  define PATH_MAX 1024
  # endif
  #endif
  #if PATH_MAX + 0 < 1024
  # undef PATH_MAX
  # define PATH_MAX 1024
  #endif
  
  uz
  su_file_name_max(char const *dname){
     uz rv;
  #ifdef HAVE_PATHCONF
     long sr;
  #endif
     NYD_IN;
     UNUSED(dname);
     ASSERT_NYD(dname != NIL, rv = NAME_MAX);
  
  #ifdef HAVE_PATHCONF
     if((sr = pathconf(dname, _PC_NAME_MAX)) != -1)
        rv = S(uz,sr);
     else
  #endif
        rv = NAME_MAX;

     NYD_OU;
     return rv;
  }
  
  uz
  su_path_name_max(char const *dname_or_nil){
     uz rv;
  #ifdef HAVE_PATHCONF
     long rv;
  #endif
     NYD_IN;
     UNUSED(dname_or_nil);
  
  #ifdef HAVE_PATHCONF
     if(dname_or_nil == NIL)
        dname_or_nil = "/"; /* TODO dirsep configurable */
  
     if((sr = pathconf(dname_or_nil, _PC_PATH_MAX)) != -1)
        rv = S(uz,sr);
     else
  #endif
        rv = PATH_MAX;

     NYD_OU;
     return rv;
  }

Note also -1 not < 1.  Hmm.
I have in FIXME

  ->su/io.h: Windows: FILENAME_MAX in 
stdio.h;stdlib.h:_MAX_DIR,_MAX_DRIVE,_MAX_FNAME,_MAX_PATH

So for going Cygwin (isn't it going to die now that Windows seems
to ship an entire Linux subsystem all the time?  I have no idea!!)
i was thinking about the latter things in the #ifndef paths.

Good night,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]