[PATCH] avoid assuming MAXPATHLEN in config(8)

Robert Millan rmh at debian.org
Thu Jul 7 11:12:03 UTC 2011


2011/7/7 Ed Schouten <ed at 80386.nl>:
> * Robert Millan <rmh at debian.org>, 20110707 11:33:
>> config(8) assumes MAXPATHLEN is defined in a few places, but presence
>> of this macro isn't garanteed (POSIX says that it is only present when
>> a file length limit exists, which may not be the case).
>
> Even though it is good to make our code conform to standards as much as
> possible, do keep in mind that your patch also causes a lot of
> regressions in that area. The code now uses asprintf(), which is not
> part of POSIX. I also think the use of __GLIBC__ is frowned upon.

Uhm... you're right.  Actually I knew asprintf() is not part of POSIX,
it just didn't occur to me that this contradicted my point about
MAXPATHLEN [1].

As for the __GLIBC__ bit, it is difficult to handle this without a
function that canonicalizes arbitrary-length pathnames.  Would you
prefer something like:

#ifdef MAXPATHLEN
// use realpath on a statically-allocated buffer
#else
// assume canonicalize_file_name() is present
#endif

[1] Btw, POSIX itself is quite contradictory too: it doesn't let you
assume MAXPATHLEN, but it doesn't give you the facilities you need in
case it isn't present (e.g. asprintf and canonicalize_file_name but
gethostname and getline / fgetln come to mind too).

-- 
Robert Millan


More information about the freebsd-hackers mailing list