OSDN Git Service

lseek: Correct order of offset arguments
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / open.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * open() for uClibc
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11 #include <fcntl.h>
12 #include <stdarg.h>
13 #include <cancel.h>
14
15 #if defined __NR_open
16 # define __NR___syscall_open __NR_open
17 static __always_inline _syscall3(int, __syscall_open, const char *, file,
18                                  int, flags, __kernel_mode_t, mode)
19 strong_alias_untyped(__syscall_open,__NC(open))
20
21 # define __NR___open2_nocancel __NR_open
22 _syscall2(int, __NC(open2), const char *, file, int, flags)
23 #else
24 int __open2_nocancel(const char *, int) __nonnull ((1)) attribute_hidden;
25 int __open_nocancel(const char *, int, mode_t) __nonnull ((1)) attribute_hidden;
26 #endif
27
28 int open(const char *file, int oflag, ...)
29 {
30         mode_t mode = 0;
31
32         if (oflag & O_CREAT) {
33                 va_list arg;
34                 va_start(arg, oflag);
35                 mode = va_arg(arg, mode_t);
36                 va_end(arg);
37         }
38
39         if (SINGLE_THREAD_P)
40 #if defined(__NR_open)
41                 return __NC(open)(file, oflag, mode);
42 #elif defined(__NR_openat)
43                 return openat(AT_FDCWD, file, oflag, mode);
44 #endif
45
46 #ifdef __NEW_THREADS
47         int oldtype = LIBC_CANCEL_ASYNC ();
48 # if defined(__NR_open)
49         int result = __NC(open)(file, oflag, mode);
50 # else
51         int result = openat(AT_FDCWD, file, oflag, mode);
52 # endif
53         LIBC_CANCEL_RESET (oldtype);
54         return result;
55 #endif
56 }
57 lt_strong_alias(open)
58 lt_libc_hidden(open)
59 #if !defined(__NR_open)
60 strong_alias_untyped(open,__open2_nocancel)
61 strong_alias_untyped(open,__open_nocancel)
62 #endif