]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(rpl_openat): Also accept optional mode parameter.
authorJim Meyering <jim@meyering.net>
Sun, 28 Nov 2004 22:41:57 +0000 (22:41 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 28 Nov 2004 22:41:57 +0000 (22:41 +0000)
lib/openat.c

index a3650f9c60f76723e23a5c7da572a9b1ca97a867..69370ce2c8f0564f844add9e3b3a97d738b3e254 100644 (file)
@@ -25,6 +25,7 @@
 #undef openat
 
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 
-// FIXME
-// int openat (int fildes, const char *path, int oflag, /* mode_t mode */...);
-
 /* Replacement for Solaris' openat function.
    <http://www.google.com/search?q=openat+site:docs.sun.com>
    Simulate it by doing save_cwd/fchdir/open/restore_cwd.
    If either the fchdir or the restore_cwd fails, then exit nonzero.  */
 int
-rpl_openat (int fd, char const *filename, int flags)
+rpl_openat (int fd, char const *filename, int flags, ...)
 {
   struct saved_cwd saved_cwd;
   int saved_errno = 0;
   int new_fd;
+  mode_t mode;
+
+  if (flags & O_CREAT)
+    {
+      va_list arg;
+      va_start (arg, flags);
+      mode = va_arg (arg, mode_t);
+      va_end (arg);
+    }
+  else
+    {
+      mode = 0;
+    }
 
   if (fd == AT_FDCWD || *filename == '/')
-    return open (filename, flags);
+    return open (filename, flags, mode);
 
   if (save_cwd (&saved_cwd) != 0)
     error (EXIT_FAILURE, errno,
@@ -63,7 +74,7 @@ rpl_openat (int fd, char const *filename, int flags)
       return -1;
     }
 
-  new_fd = open (filename, flags);
+  new_fd = open (filename, flags, mode);
   if (new_fd < 0)
     saved_errno = errno;