bug-gnulib
[Top][All Lists]
Advanced

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

Re: dirname module calls AC_LIBOBJ unconditionally


From: Eric Blake
Subject: Re: dirname module calls AC_LIBOBJ unconditionally
Date: Thu, 22 Dec 2005 22:14:55 +0000

> The gl_DIRNAME macro (in dirname.m4) calls AC_LIBOBJ([dirname])
> unconditionally, without testing for a working dirname implementation.

The dirname module provides dir_name and base_name, not
dirname and basename.  The reason for this is that POSIX
does not allow dirname() or basename() to malloc their results,
but allows the implementation to choose between modifying the
input string (not good for read-only input) or using static storage
(not threadsafe).  This means that basename() and dirname()
are inherently non-portable, even though they are standardized.

So experience in gnulib has shown that slightly different semantics,
with dir_name that always mallocs, and (when my patch from a
month ago is approved) base_name that mallocs and last_component
that returns a pointer to the middle of the input string, is more
usable.  To get these useful semantics, the replacement must
always happen.

> 
> Also, the dirname module provides a basename implementation, but there
> is no basename.m4 that would test for this specific function.
> 
> I need to provide a replacement for basename in case this function is
> missing or broken. Although my own system has a working basename, the
> portability library is always built.

Don't use basename.  If you use gnulib, use base_name, with
its one-off semantics.

> 
> It seems two things are required: Adding a basename.m4, and writing a
> test for a working basename implementation, calling
> AC_LIBOBJ([basename]) on failure only. I would be grateful for any
> hints how to do this.

basename.m4 is not required, since the dirname module is
meant to be used as a group and does not replace any
missing/broken standardized functions.

> 
> Claudio
--
Eric Blake




reply via email to

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