fcntl.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _FCNTL_C
  18. #define _FCNTL_C
  19. #ifdef __M2__
  20. #if __uefi__
  21. #include <uefi/fcntl.c>
  22. #elif __i386__
  23. #include <x86/linux/fcntl.c>
  24. #elif __x86_64__
  25. #include <amd64/linux/fcntl.c>
  26. #elif __arm__
  27. #include <armv7l/linux/fcntl.c>
  28. #elif __aarch64__
  29. #include <aarch64/linux/fcntl.c>
  30. #elif __riscv && __riscv_xlen==32
  31. #include <riscv32/linux/fcntl.c>
  32. #elif __riscv && __riscv_xlen==64
  33. #include <riscv64/linux/fcntl.c>
  34. #elif __knight_posix__
  35. #include <knight/linux/fcntl.c>
  36. #elif __knight__
  37. #include <knight/native/fcntl.c>
  38. #else
  39. #error arch not supported
  40. #endif
  41. #else
  42. extern int _open(char* name, int flag, int mode);
  43. #endif
  44. int errno;
  45. int open(char* name, int flag, int mode)
  46. {
  47. int fd = _open(name, flag, mode);
  48. if(0 > fd)
  49. {
  50. errno = -fd;
  51. fd = -1;
  52. }
  53. return fd;
  54. }
  55. #endif