Hi Jim,

> > In summary, I like Pino's 'getprogname' module because it nicely solves the
> > problems he listed in
> > http://lists.gnu.org/archive/html/bug-gnulib/2016-03/msg00048.html.
> >
> > But I disagree with the idea that the 'program_name' module and the
> > set_program_name() function should be deprecated, as expressed in
> > https://lists.gnu.org/archive/html/bug-gnulib/2016-09/msg00007.html
> 
> Hi Bruno,
> 
> I did not mean to imply by that message that we should eliminate every
> use of the program_name module. My desire is more to avoid accidental
> use of it when the getprogname module would be more appropriate.

Fully agree on this.

The way I currently see it, the two modules serve different purposes
and it's easy to decide which one to use in which case:

  * In a program's main() function, and associated usage() and help()
    functions, use set_program_name and program_name.

    Rationale: This provides the full name of the executable, and discards
    the "lt-" prefix.

  * In library code, or more generally any code that is not near the
    main() function, use getprogname().

    Rationale: This makes it possible to put this library code under LGPL
    and avoid the many linker errors to 'program_name' that people have
    been seeing.

The only remaining problems are:

  1) The test-getprogname failure when added to a package that uses libtool,
     e.g. GNU gettext.
     $ ./test-getprogname
     lt-test-getprogname: test-getprogname.c:29: main: Assertion 
`(__extension__ ...)' failed.

  2) Error messages printed by programs in the source tree (before
     'make install') will show "lt-prog" instead of "prog".

About 1): This can be fixed through a change, below. Proposed.
About 2): This should be fixed in libtool's ltmain.sh. I don't think it's
gnulib's business to override BSD's getprogname() just because of a libtool
quirk.


2016-10-18  Bruno Haible  <br...@clisp.org>

        getprogname tests: Avoid failure in packages that use libtool.
        * tests/test-getprogname.c (main): Strip "lt-" prefix.
        Based on a patch by Jim Meyering.

diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c
index b39ab37..103b58c 100644
--- a/tests/test-getprogname.c
+++ b/tests/test-getprogname.c
@@ -27,6 +27,13 @@ main (void)
 {
   char const *p = getprogname ();
 
+  /* libtool creates a temporary executable whose name is sometimes prefixed
+     with "lt-" (depends on the platform).  But the name of the temporary
+     executable is a detail that should not be visible to the end user and to
+     the test suite.  Remove this "lt-" prefix here.  */
+  if (strncmp (p, "lt-", 3) == 0)
+    p = p + 3;
+
   /* Note: You can make this test fail
      a) by running it on a case-insensitive file system (such as on Windows,
         Cygwin, or on Mac OS X with a case-insensitive HFS+ file system),


Reply via email to