bug-gnulib
[Top][All Lists]
Advanced

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

getprogname: comments and test failure on Cygwin


From: Bruno Haible
Subject: getprogname: comments and test failure on Cygwin
Date: Sun, 16 Oct 2016 13:55:18 +0200
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

Hi,

The 'getprogname' module test fails on Cygwin 2.6, because the returned
value is "test-getprogname", not "test-getprogname.exe". (On mingw, on the
other hand, it really is "test-getprogname.exe".)

Also, while at it, I'd like to add comments:
1. The declaration in getprogname.h does not state what the function does
   or return.
2. In getprogname.c it is hard to understand which code is used for which
   platform.
3. In test-getprogname.c there is no explanation why the file name is compared
   with strcmp and not strcasecmp.

Here's a proposed patch.

Bruno


2016-10-16  Bruno Haible  <address@hidden>

        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.

diff --git a/lib/getprogname.h b/lib/getprogname.h
index 36b8ba8..559b1f2 100644
--- a/lib/getprogname.h
+++ b/lib/getprogname.h
@@ -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
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 0e8d963..ec2c948 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -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
+{Minix 3.1.8, IRIX 6.5, OSF/1 5.1, Interix 3.5.
+# 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;
diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c
index 6e3f694..b39ab37 100644
--- a/tests/test-getprogname.c
+++ b/tests/test-getprogname.c
@@ -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;
 }




reply via email to

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