summaryrefslogtreecommitdiff
path: root/lib/openat.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-11-28 22:41:57 +0000
committerJim Meyering <jim@meyering.net>2004-11-28 22:41:57 +0000
commit26b53ffffe8a1e5443e632ae5472e8e2cc92ad80 (patch)
tree7225ecbc3c9d2bc927fa73a41c693255df7a2240 /lib/openat.c
parentfd6af25d9ae36aff003421ad1e2b0102de61a903 (diff)
downloadcoreutils-26b53ffffe8a1e5443e632ae5472e8e2cc92ad80.tar.xz
(rpl_openat): Also accept optional mode parameter.
Diffstat (limited to 'lib/openat.c')
-rw-r--r--lib/openat.c23
1 files changed, 17 insertions, 6 deletions
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 <stdlib.h>
+#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
@@ -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.
<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;