]> Savannah Git Hosting - gnulib.git/commitdiff
at-internal: Fix support for z/OS.
authorBruno Haible <bruno@clisp.org>
Mon, 30 Jan 2023 22:10:21 +0000 (23:10 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Feb 2023 02:28:59 +0000 (03:28 +0100)
* lib/openat-proc.c (openat_proc_name) [z/OS]: Proper error handling.
Convert only the relevant part of the dir[] buffer.

ChangeLog
lib/openat-proc.c

index 2a34f44ffe43f819ed9bdb309ceaa8063f748e61..192e6e26a9950785a9de3e976e19d6fdc729ea9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-01-30  Bruno Haible  <bruno@clisp.org>
 
+       at-internal: Fix support for z/OS.
+       * lib/openat-proc.c (openat_proc_name) [z/OS]: Proper error handling.
+       Convert only the relevant part of the dir[] buffer.
+
        at-internal: Add support for z/OS.
        Reported and draft patch by Igor Todorovski <itodorov@ca.ibm.com>.
        * lib/openat-proc.c [z/OS]: Include <termios.h>.
index 6419a8cf5fb70c96f260c0a9972435d3fdc70bc7..88f70be4f59f4adb15f8892324d8d5dfef62e736 100644 (file)
@@ -123,8 +123,16 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
 # endif
 # ifdef __MVS__
     char dir[_XOPEN_PATH_MAX];
-    if (w_ioctl (fd, _IOCC_GPN, sizeof dir, dir) == 0)
-      __e2a_l (dir, sizeof dir);
+    /* Documentation:
+       https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-w-ioctl-w-pioctl-control-devices */
+    if (w_ioctl (fd, _IOCC_GPN, sizeof dir, dir) < 0)
+      return NULL;
+    /* Documentation:
+       https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-e2a-l-convert-characters-from-ebcdic-ascii */
+    dirlen = __e2a_l (dir, strlen (dir));
+    if (dirlen < 0 || dirlen >= sizeof dir)
+      return NULL;
+    dir[dirlen] = '\0';
 # endif
 
     dirlen = strlen (dir);