bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Z/OS Enhancement to gnu lib
@ 2023-01-30  4:09 Igor Todorovski
  2023-01-30 11:48 ` Bruno Haible
  0 siblings, 1 reply; 4+ messages in thread
From: Igor Todorovski @ 2023-01-30  4:09 UTC (permalink / raw)
  To: bug-gnulib@gnu.org, Mike Fulton

[-- Attachment #1: Type: text/plain, Size: 1924 bytes --]

Hi,

I was wondering if the following changes I made to findutils (to get it to function on z/OS) can be merged into gnulib.

The first change (fdopendir.c) guards the close call. Otherwise we get a bad file descriptor on z/OS. I am not sure if this has any other consequences, but so far I haven’t seen any issues with findutils.

The second change (openat-proc.c) adds a way to get the pathname when given a file descriptor as an input.

If you have any comments, please let me know:

index c2b0e1e..82ae2e4 100644
--- a/gl/lib/fdopendir.c
+++ b/gl/lib/fdopendir.c
@@ -151,7 +151,9 @@ fdopendir_with_dup (int fd, int older_dupfd, struct saved_cwd const *cwd)
         }
       else
         {
+#ifndef __MVS__
           close (fd);
+#endif
           dir = fd_clone_opendir (dupfd, cwd);
           saved_errno = errno;
           if (! dir)
diff --git a/gl/lib/openat-proc.c b/gl/lib/openat-proc.c
index 3bacf7d..bb788fd 100644
--- a/gl/lib/openat-proc.c
+++ b/gl/lib/openat-proc.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <unistd.h>
 #ifdef __KLIBC__
@@ -53,7 +54,27 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
       return buf;
     }
-#ifndef __KLIBC__
+#ifdef __MVS__
+  {
+    char dir[_XOPEN_PATH_MAX];
+    int rc = w_ioctl(fd, _IOCC_GPN, _XOPEN_PATH_MAX, dir);
+    if (rc == 0) {
+      __e2a_l(dir, _XOPEN_PATH_MAX);
+    }
+    size_t bufsize;
+    dirlen = strlen (dir);
+    bufsize = dirlen + 1 + strlen (file) + 1; /* 1 for '/', 1 for null */
+    if (OPENAT_BUFFER_SIZE < bufsize)
+      {
+        result = malloc (bufsize);
+        if (! result)
+          return NULL;
+      }
+
+    strcpy (result, dir);
+    result[dirlen++] = '/';
+  }
+#elif !defined( __KLIBC__)
# define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/"
   {
     enum {


[-- Attachment #2: Type: text/html, Size: 14454 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-30 22:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30  4:09 Z/OS Enhancement to gnu lib Igor Todorovski
2023-01-30 11:48 ` Bruno Haible
2023-01-30 17:29   ` Igor Todorovski
2023-01-30 22:12     ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).