From 26b53ffffe8a1e5443e632ae5472e8e2cc92ad80 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 28 Nov 2004 22:41:57 +0000 Subject: (rpl_openat): Also accept optional mode parameter. --- lib/openat.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib/openat.c') diff --git a/lib/openat.c b/lib/openat.c index a3650f9c6..69370ce2c 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -25,6 +25,7 @@ #undef openat #include +#include #include #include #include @@ -37,22 +38,32 @@ #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. 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; -- cgit v1.2.3-54-g00ecf