projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Avoid test failures on AIX and OSF/1.
[gnulib.git]
/
lib
/
open.c
diff --git
a/lib/open.c
b/lib/open.c
index
317fb8a
..
13af274
100644
(file)
--- a/
lib/open.c
+++ b/
lib/open.c
@@
-18,21
+18,29
@@
#include <config.h>
#include <config.h>
-/* Specification. */
+/* Get the original definition of open. It might be defined as a macro. */
+#define __need_system_fcntl_h
#include <fcntl.h>
#include <fcntl.h>
+#undef __need_system_fcntl_h
+#include <sys/types.h>
-/* If the fchdir replacement is used, open() is defined in fchdir.c. */
-#ifndef FCHDIR_REPLACEMENT
+static inline int
+orig_open (const char *filename, int flags, mode_t mode)
+{
+ return open (filename, flags, mode);
+}
-# include <errno.h>
-# include <stdarg.h>
-# include <string.h>
-# include <sys/types.h>
-# include <sys/stat.h>
+/* Specification. */
+#include <fcntl.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
int
open (const char *filename, int flags, ...)
int
open (const char *filename, int flags, ...)
-# undef open
{
mode_t mode;
int fd;
{
mode_t mode;
int fd;
@@
-53,12
+61,12
@@
open (const char *filename, int flags, ...)
va_end (arg);
}
va_end (arg);
}
-#
if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
if (strcmp (filename, "/dev/null") == 0)
filename = "NUL";
if (strcmp (filename, "/dev/null") == 0)
filename = "NUL";
-#
endif
+#endif
-#
if OPEN_TRAILING_SLASH_BUG
+#if OPEN_TRAILING_SLASH_BUG
/* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
is specified, then fail.
Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
/* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
is specified, then fail.
Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
@@
-89,11
+97,11
@@
open (const char *filename, int flags, ...)
return -1;
}
}
return -1;
}
}
-#
endif
+#endif
- fd = open (filename, flags, mode);
+ fd = o
rig_o
pen (filename, flags, mode);
-#
if OPEN_TRAILING_SLASH_BUG
+#if OPEN_TRAILING_SLASH_BUG
/* If the filename ends in a slash and fd does not refer to a directory,
then fail.
Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
/* If the filename ends in a slash and fd does not refer to a directory,
then fail.
Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
@@
-115,13
+123,18
@@
open (const char *filename, int flags, ...)
if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
{
if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
{
+ close (fd);
errno = ENOTDIR;
return -1;
}
}
}
errno = ENOTDIR;
return -1;
}
}
}
-# endif
+#endif
+
+#ifdef FCHDIR_REPLACEMENT
+ if (fd >= 0)
+ _gl_register_fd (fd, filename);
+#endif
return fd;
}
return fd;
}
-#endif