changeset 18461:66921c9564c8

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 16 Oct 2016 13:53:18 +0200
parents ee6a8d3b3a4c
children b6c7fb1f9e0c
files ChangeLog lib/getprogname.c lib/getprogname.h tests/test-getprogname.c
diffstat 4 files changed, 41 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Oct 16 20:07:37 2016 +0200
+++ b/ChangeLog	Sun Oct 16 13:53:18 2016 +0200
@@ -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
--- a/lib/getprogname.c	Sun Oct 16 20:07:37 2016 +0200
+++ b/lib/getprogname.c	Sun Oct 16 13:53:18 2016 +0200
@@ -38,24 +38,29 @@
 
 #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 @@
   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 @@
         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;
--- a/lib/getprogname.h	Sun Oct 16 20:07:37 2016 +0200
+++ b/lib/getprogname.h	Sun Oct 16 13:53:18 2016 +0200
@@ -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
--- a/tests/test-getprogname.c	Sun Oct 16 20:07:37 2016 +0200
+++ b/tests/test-getprogname.c	Sun Oct 16 13:53:18 2016 +0200
@@ -26,6 +26,22 @@
 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;
 }