autoconf
[Top][All Lists]
Advanced

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

Re: How to write a conditional test in configure.ac


From: Svante Signell
Subject: Re: How to write a conditional test in configure.ac
Date: Fri, 13 Jan 2012 03:19:27 +0100

Thank you for your (and Mikes) prompt replies.
On Thu, 2012-01-12 at 16:32 -0700, Eric Blake wrote:
> On 01/12/2012 03:58 PM, Svante Signell wrote:
> > Hello.
> > 
> > Consider the code snippet below. How to modify it to get the GNU version
> > of baseline if defined (in my case GNU/Hurd). The macro 
> > AC_USE_SYSTEM_EXTENSIONS is stated earlier in configure.ac.

/baseline/basename/

> First, I'd suggest that you _don't_ use basename(); it has severe
> portability problems (POSIX allows, but does not require, it to modify
> its incoming argument; worse, POSIX states that these functions need not
> be thread-safe, rendering them useless in multithreaded programs) - mere
> existence of the function in libgen.h does not tell you whether you will
> be encountering those subtle differences as you port to other platforms.
>  Besides, on glibc, there are two flavors of basename(), and which
> version you get depends on your compile-time options - I guess this is a
> case where you were probing for the GNU behavior rather than the POSIX
> behavior.  

Yes I want the GNU version, see below.

> Your test program didn't test for those particular
> subtleties.  The gnulib module dirname provides functions dir_name,
> base_name, and last_component, which have saner semantics that are
> uniform to all platforms and not dependent on POSIX vagaries.

This code is not mine, it comes from a package called libtar. Latest
release was in 2003, and there is no upstream any longer. Still some
other packages depends on this code. I'm merely porting the code to get
rid of all MAXPATHLEN definitions, since this is not defined for
GNU/Hurd. And by doing dynamic allocation of strings, modification of
the argument strikes hard freeing allocated strings since the fallback
solution is just the openbsd version! :(

Cite:
On Thursday 12 January 2012 18:32:15 Eric Blake wrote:
> First, I'd suggest that you _don't_ use basename(); it has severe
> portability problems (POSIX allows, but does not require, it to modify
> its incoming argument
and some systems (like some *BSDs) do modify it :(
-mike

All fallback (compat) code are openbsd versions, and I don't want to
port them removing the fixed length strings by dynamic ones since much
better alternatives already exists in glibc.

> But, if I can't convince you to use gnulib and either base_name() or
> last_component(), I can still advise you on how to better use autoconf.

gnulib is not used in this code, so that is not an option. And thanks!

> I would have written:
> 
> AC_DEFUN([COMPAT_FUNC_BASENAME], [
...
Will this code give the GNU version of basename if defined, the POSIX
version if not defined, and the openbsd fallback as last resort?

Another issue with the code is is that the test a flawed, but I know how
to correct it.





reply via email to

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