bug-gnulib
[Top][All Lists]
Advanced

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

Re: set_program_name behavior


From: Bruno Haible
Subject: Re: set_program_name behavior
Date: Wed, 14 Jan 2009 22:51:46 +0100
User-agent: KMail/1.9.9

Hello Sergey,

> The behavior of set_program_name differs depending on whether argv[0]
> refers to a libtool script (*/.libs/lt-*) or to a usual binary. In the first
> case, the function strips off all directory components and the `lt-'
> prefix, and assigns the result to program_name. In the second case,
> however, it does nothing and assings unchanged argv[0] to
> program_name. Is this intentional?

Yes, this is intentional. The idea is that program_name is being used in
error messages, so when the user runs

  /some/hidden/place/bin/cp foo foo

he should get

  /some/hidden/place/bin/cp: `foo' and `foo' are the same file

because simply

  cp: `foo' and `foo' are the same file

would be misleading. (The would start looking for 'cp' in his PATH...)

The removal of */.libs/lt- prefixes is done so that "make check" produces
reliable results, and because the precise location of the executable used
under the hood by libtool is a detail that the user should not know about.
(Remember the need to use "./libtool --mode=execute gdb cp". Btw, I find
the need to mention --mode=execute explicitly really painful. As if the
command 'gdb' was not well known...)

> It would be logical if it removed directory components in both cases.

That would not be useful for end users, see above. In unit tests, you
better drop the entire executable name before comparing the output.

Bruno


2009-01-14  Bruno Haible  <address@hidden>

        * lib/progname.c (set_program_name): Add more comments.
        Reported by Sergey Poznyakoff <address@hidden>.

--- lib/progname.c.orig 2009-01-14 22:50:59.000000000 +0100
+++ lib/progname.c      2009-01-14 22:38:06.000000000 +0100
@@ -1,5 +1,5 @@
 /* Program name management.
-   Copyright (C) 2001-2003, 2005-2008 Free Software Foundation, Inc.
+   Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
    Written by Bruno Haible <address@hidden>, 2001.
 
    This program is free software: you can redistribute it and/or modify
@@ -35,6 +35,8 @@
 {
   /* libtool creates a temporary executable whose name is sometimes prefixed
      with "lt-" (depends on the platform).  It also makes argv[0] absolute.
+     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 "<dirname>/.libs/" or "<dirname>/.libs/lt-" prefix here.  */
   const char *slash;
   const char *base;
@@ -47,5 +49,15 @@
       if (strncmp (base, "lt-", 3) == 0)
        argv0 = base + 3;
     }
+
+  /* But don't strip off a leading <dirname>/ in general, because when the user
+     runs
+         /some/hidden/place/bin/cp foo foo
+     he should get the error message
+         /some/hidden/place/bin/cp: `foo' and `foo' are the same file
+     not
+         cp: `foo' and `foo' are the same file
+   */
+
   program_name = argv0;
 }




reply via email to

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