open.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <sys/syscall.h>
  10. #include <fcntl.h>
  11. #include <stdarg.h>
  12. #include <cancel.h>
  13. #if defined __NR_open
  14. # define __NR___syscall_open __NR_open
  15. static __always_inline _syscall3(int, __syscall_open, const char *, file,
  16. int, flags, __kernel_mode_t, mode)
  17. strong_alias_untyped(__syscall_open,__NC(open))
  18. # define __NR___open2_nocancel __NR_open
  19. _syscall2(int, __NC(open2), const char *, file, int, flags)
  20. #else
  21. int __open2_nocancel(const char *, int) __nonnull ((1)) attribute_hidden;
  22. int __open_nocancel(const char *, int, mode_t) __nonnull ((1)) attribute_hidden;
  23. #endif
  24. int open(const char *file, int oflag, ...)
  25. {
  26. mode_t mode = 0;
  27. #ifdef __NEW_THREADS
  28. int oldtype, result;
  29. #endif
  30. if (oflag & O_CREAT) {
  31. va_list arg;
  32. va_start(arg, oflag);
  33. mode = va_arg(arg, mode_t);
  34. va_end(arg);
  35. }
  36. if (SINGLE_THREAD_P)
  37. #if defined(__NR_open)
  38. return __NC(open)(file, oflag, mode);
  39. #elif defined(__NR_openat)
  40. return openat(AT_FDCWD, file, oflag, mode);
  41. #endif
  42. #ifdef __NEW_THREADS
  43. oldtype = LIBC_CANCEL_ASYNC ();
  44. # if defined(__NR_open)
  45. result = __NC(open)(file, oflag, mode);
  46. # else
  47. result = openat(AT_FDCWD, file, oflag, mode);
  48. # endif
  49. LIBC_CANCEL_RESET (oldtype);
  50. return result;
  51. #endif
  52. }
  53. lt_strong_alias(open)
  54. lt_libc_hidden(open)
  55. #if !defined(__NR_open)
  56. int __open2_nocancel(const char *file, int oflag)
  57. {
  58. return open(file, oflag);
  59. }
  60. int __open_nocancel(const char *file, int oflag, mode_t mode)
  61. {
  62. return open(file, oflag, mode);
  63. }
  64. #endif