]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: Add support for ASCII-compatible environments in z/OS.
authorBruno Haible <bruno@clisp.org>
Thu, 1 Jun 2023 14:18:02 +0000 (16:18 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 4 Jun 2023 19:19:50 +0000 (21:19 +0200)
Reported by Mike Fulton <mikefultonpersonal@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-05/msg00198.html>.

* lib/getprogname.c (getprogname): On z/OS, when compiling for an
ASCII-compatible environment, convert the result from EBCDIC to ASCII.

ChangeLog
lib/getprogname.c

index 0ce7a07bb18554d4cb376d4c1035cc57ea2199b5..a133b4c6b5d68990bc501e473e9812d46113657b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-06-01  Bruno Haible  <bruno@clisp.org>
+
+       getprogname: Add support for ASCII-compatible environments in z/OS.
+       Reported by Mike Fulton <mikefultonpersonal@gmail.com> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2023-05/msg00198.html>.
+       * lib/getprogname.c (getprogname): On z/OS, when compiling for an
+       ASCII-compatible environment, convert the result from EBCDIC to ASCII.
+
 2023-05-30  Nick Bowler  <nbowler@draconx.ca>
 
        readline: fix memory leak in replacement readline.
index 62a480046e932f022d1c12bd0c11d58f8cf92fd1..a56261e13b45c84cb92df10bbc4b7934995cf9d8 100644 (file)
@@ -1,5 +1,5 @@
 /* Program name management.
-   Copyright (C) 2016-2022 Free Software Foundation, Inc.
+   Copyright (C) 2016-2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -214,7 +214,19 @@ getprogname (void)
                 {
                   char *s = strdup (last_component (buf.ps_pathptr));
                   if (s)
-                    p = s;
+                    {
+#  if defined __XPLINK__ && __CHARSET_LIB == 1
+                      /* The compiler option -qascii is in use.
+                         https://makingdeveloperslivesbetter.wordpress.com/2022/01/07/is-z-os-ascii-or-ebcdic-yes/
+                         https://www.ibm.com/docs/en/zos/2.5.0?topic=features-macros-related-compiler-option-settings
+                         So, convert the result from EBCDIC to ASCII.
+                         https://www.ibm.com/docs/en/zos/2.5.0?topic=functions-e2a-s-convert-string-from-ebcdic-ascii */
+                      if (__e2a_s (s) == (size_t)-1)
+                        free (s);
+                      else
+#  endif
+                        p = s;
+                    }
                   break;
                 }
             }