fcntl.c 503 B

123456789101112131415161718192021222324252627
  1. #include <stdarg.h>
  2. #include <errno.h>
  3. #include <fcntl.h>
  4. #include <syscall.h>
  5. #include <sys/types.h>
  6. int open(const char* filename, int flags, ...)
  7. {
  8. int ret;
  9. if (flags | O_CREAT) {
  10. va_list vl;
  11. va_start(vl, flags);
  12. ret = syscall3(SYS_open, (uint32_t)filename, flags, va_arg(vl, int));
  13. va_end(vl);
  14. }
  15. else
  16. ret = syscall2(SYS_open, (uint32_t)filename, flags);
  17. if (ret < 0) {
  18. errno = -ret;
  19. return -1;
  20. }
  21. return ret;
  22. }