1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-08-04 07:43:58 +02:00

(rpl_openat): Also accept optional mode parameter.

This commit is contained in:
Jim Meyering
2004-11-28 22:41:57 +00:00
parent fd6af25d9a
commit 26b53ffffe
+17 -6
View File
@@ -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;