diff options
author | Mikael Pettersson <mikpe@it.uu.se> | 2011-01-29 17:37:18 +0000 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2011-01-30 21:18:11 +0100 |
commit | 0b40b7a7f71a773b606369e71fff8a6fbe22dbdf (patch) | |
tree | 3bddb15be51b4116a6bf8974a4dc4408af32f2e4 | |
parent | e572c420685a9878c5a61968567a2b2d64bfeeb2 (diff) | |
download | klibc-0b40b7a7f71a773b606369e71fff8a6fbe22dbdf.tar.gz |
[klibc] Use <stdarg.h> features in open() and openat()
Looking in klibc-1.5.21 I see that the published prototype for open() is:
__extern int open(const char *, int, ...);
This looks fine, but the actual definition (which deliberately doesn't see the
above prototype) is:
int open(const char *pathname, int flags, mode_t mode)
{ ... }
This is invalid C, and very sloppy programming.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47533
Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
Signed-off-by: Thorsten Glaser <tg@mirbsd.de>
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/include/fcntl.h | 2 | ||||
-rw-r--r-- | usr/include/unistd.h | 2 | ||||
-rw-r--r-- | usr/klibc/open.c | 14 | ||||
-rw-r--r-- | usr/klibc/openat.c | 14 |
4 files changed, 24 insertions, 8 deletions
diff --git a/usr/include/fcntl.h b/usr/include/fcntl.h index 0908e2174d0d5..c94b2be371d98 100644 --- a/usr/include/fcntl.h +++ b/usr/include/fcntl.h @@ -35,10 +35,8 @@ #endif /* This is defined here as well as in <unistd.h> */ -#ifndef _KLIBC_IN_OPEN_C __extern int open(const char *, int, ...); __extern int openat(int, const char *, int, ...); -#endif __extern int creat(const char *, mode_t); __extern int fcntl(int, int, ...); diff --git a/usr/include/unistd.h b/usr/include/unistd.h index 97760d4eb4995..0d3205e1cd08f 100644 --- a/usr/include/unistd.h +++ b/usr/include/unistd.h @@ -82,10 +82,8 @@ __extern int lchown(const char *, uid_t, gid_t); __extern char *getcwd(char *, size_t); /* Also in <fcntl.h> */ -#ifndef _KLIBC_IN_OPEN_C __extern int open(const char *, int, ...); __extern int openat(int, const char *, int, ...); -#endif __extern int creat(const char *, mode_t); __extern int open_cloexec(const char *, int, mode_t); __extern int close(int); diff --git a/usr/klibc/open.c b/usr/klibc/open.c index 9b0897a77927a..290f9590892d6 100644 --- a/usr/klibc/open.c +++ b/usr/klibc/open.c @@ -5,17 +5,27 @@ * system call, to indicate that we're 64-bit safe. */ -#define _KLIBC_IN_OPEN_C #include <unistd.h> #include <fcntl.h> #include <bitsize.h> +#include <stdarg.h> #if _BITSIZE == 32 && !defined(__i386__) extern int __open(const char *, int, mode_t); -int open(const char *pathname, int flags, mode_t mode) +int open(const char *pathname, int flags, ...) { + mode_t mode = 0; + + if (flags & O_CREAT) { + va_list ap; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + return __open(pathname, flags | O_LARGEFILE, mode); } diff --git a/usr/klibc/openat.c b/usr/klibc/openat.c index 83c87cd49b1f4..0609b832c1858 100644 --- a/usr/klibc/openat.c +++ b/usr/klibc/openat.c @@ -5,17 +5,27 @@ * system call, to indicate that we're 64-bit safe. */ -#define _KLIBC_IN_OPEN_C #include <unistd.h> #include <fcntl.h> #include <bitsize.h> +#include <stdarg.h> #if _BITSIZE == 32 && !defined(__i386__) && defined(__NR_openat) extern int __openat(int, const char *, int, mode_t); -int openat(int dirfd, const char *pathname, int flags, mode_t mode) +int openat(int dirfd, const char *pathname, int flags, ...) { + mode_t mode = 0; + + if (flags & O_CREAT) { + va_list ap; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + return __openat(dirfd, pathname, flags | O_LARGEFILE, mode); } |