open.c 1.6 KB

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