open.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if (oflag & O_CREAT) {
  28. va_list arg;
  29. va_start(arg, oflag);
  30. mode = va_arg(arg, mode_t);
  31. va_end(arg);
  32. }
  33. if (SINGLE_THREAD_P)
  34. #if defined(__NR_open)
  35. return __NC(open)(file, oflag, mode);
  36. #elif defined(__NR_openat)
  37. return openat(AT_FDCWD, file, oflag, mode);
  38. #endif
  39. #ifdef __NEW_THREADS
  40. int oldtype = LIBC_CANCEL_ASYNC ();
  41. # if defined(__NR_open)
  42. int result = __NC(open)(file, oflag, mode);
  43. # else
  44. int result = openat(AT_FDCWD, file, oflag, mode);
  45. # endif
  46. LIBC_CANCEL_RESET (oldtype);
  47. return result;
  48. #endif
  49. }
  50. lt_strong_alias(open)
  51. lt_libc_hidden(open)
  52. #if !defined(__NR_open)
  53. int __open2_nocancel(const char *file, int oflag)
  54. {
  55. return open(file, oflag);
  56. }
  57. int __open_nocancel(const char *file, int oflag, mode_t mode)
  58. {
  59. return open(file, oflag, mode);
  60. }
  61. #endif