]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: Fix test failure on Cygwin. Comments.
authorBruno Haible <bruno@clisp.org>
Sun, 16 Oct 2016 11:53:18 +0000 (13:53 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 18 Oct 2016 22:09:53 +0000 (00:09 +0200)
* lib/getprogname.h: Add comments.
* lib/getprogname.c: Add comments. Fix #elif indentation.
* tests/test-getprogname.c (main): On Cygwin, expect a result without
".exe" suffix.

ChangeLog
lib/getprogname.c
lib/getprogname.h
tests/test-getprogname.c

index f28bbb65605cc77c2d4df6b7f95d0ffb9ae6d6da..faff0427817252809489be373390811f0534858f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-10-16  Bruno Haible  <bruno@clisp.org>
+
+       getprogname: Fix test failure on Cygwin. Comments.
+       * lib/getprogname.h: Add comments.
+       * lib/getprogname.c: Add comments. Fix #elif indentation.
+       * tests/test-getprogname.c (main): On Cygwin, expect a result without
+       ".exe" suffix.
+
 2016-10-16  Bruno Haible  <bruno@clisp.org>
 
        Make sure the libunistring detection rejects older versions with a
index 0e8d963c0f3fd2ce7e204e4bd2f408208fb68d8c..47995cdc0efd8dc80c1ea8b09952a6f7a9a8367c 100644 (file)
 
 #include "dirname.h"
 
-#ifndef HAVE_GETPROGNAME
-
+#ifndef HAVE_GETPROGNAME             /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
 char const *
 getprogname (void)
 {
-# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME                /* glibc, BeOS */
+  /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
   return program_invocation_short_name;
-# elif HAVE_DECL_PROGRAM_INVOCATION_NAME
+# elif HAVE_DECL_PROGRAM_INVOCATION_NAME                    /* glibc, BeOS */
+  /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
   return last_component (program_invocation_name);
-# elif HAVE_GETEXECNAME
+# elif HAVE_GETEXECNAME                                     /* Solaris */
+  /* http://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrb1/index.html */
   const char *p = getexecname ();
   if (!p)
     p = "?";
   return last_component (p);
-# elif HAVE_DECL___ARGV
+# elif HAVE_DECL___ARGV                                     /* mingw, MSVC */
+  /* https://msdn.microsoft.com/en-us/library/dn727674.aspx */
   const char *p = __argv && __argv[0] ? __argv[0] : "?";
   return last_component (p);
-# elif HAVE_VAR___PROGNAME
+# elif HAVE_VAR___PROGNAME                                  /* OpenBSD, QNX */
+  /* http://man.openbsd.org/style.9 */
+  /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */
   /* Be careful to declare this only when we absolutely need it
      (OpenBSD 5.1), rather than when it's available.  Otherwise,
      its mere declaration makes program_invocation_short_name
@@ -63,8 +68,8 @@ getprogname (void)
   extern char *__progname;
   const char *p = __progname;
   return p && p[0] ? p : "?";
-# elif _AIX
-  /* Idea by Bastien ROUCARIÈS <address@hidden>,
+# elif _AIX                                                 /* AIX */
+  /* Idea by Bastien ROUCARIÈS,
      http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00095.html
      Reference: http://
    ibm.biz/knowctr#ssw_aix_53/com.ibm.aix.basetechref/doc/basetrf1/getprocs.htm
@@ -83,7 +88,7 @@ getprogname (void)
         p = "?";
     }
   return p;
-#elif __MVS__
+# elif __MVS__                                              /* z/OS */
   /* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm */
   static char *p = "?";
   static int first = 1;
index 36b8ba84b06dbbe4c6cd137840f2c18cb85f6501..559b1f238a33464a3d38eac42dc6c85622ef79db 100644 (file)
@@ -23,6 +23,8 @@
 extern "C" {
 #endif
 
+/* Return the base name of the executing program.
+   On native Windows this will usually end in ".exe" or ".EXE". */
 #ifndef HAVE_GETPROGNAME
 extern char const *getprogname (void)
 # ifdef HAVE_DECL_PROGRAM_INVOCATION_NAME
index 6e3f694ac1b8edf40d0e6f93424d6f34a0dc7376..b39ab37dddef688786b36aeae7821545e05382fc 100644 (file)
@@ -26,6 +26,22 @@ int
 main (void)
 {
   char const *p = getprogname ();
+
+  /* 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),
+        with an invocation that contains upper case characters, e.g.
+        test-GETPROGNAME,
+     b) by hardlinking or symlinking it to a different name (e.g. test-foo)
+        and invoking it through that name.
+     That's not the intended use. The Makefile always invokes it as
+     'test-getprogname${EXEEXT}'. */
+#if defined __CYGWIN__
+  /* The Cygwin getprogname() function strips the ".exe" suffix. */
+  assert (STREQ (p, "test-getprogname"));
+#else
   assert (STREQ (p, "test-getprogname" EXEEXT));
+#endif
+
   return 0;
 }