sysos.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2013 by Free Pascal development team
  4. This file implements all the base types and limits required
  5. for a minimal POSIX compliant subset required to port the compiler
  6. to a new OS.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program 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.
  12. **********************************************************************}
  13. function Errno2InoutRes(errno: __wasi_errno_t): Word;
  14. begin
  15. case errno of
  16. __WASI_ERRNO_NFILE,
  17. __WASI_ERRNO_MFILE:
  18. Errno2InoutRes:=4;
  19. __WASI_ERRNO_NOENT:
  20. Errno2InoutRes:=2;
  21. __WASI_ERRNO_BADF:
  22. Errno2InoutRes:=6;
  23. __WASI_ERRNO_NOMEM,
  24. __WASI_ERRNO_FAULT:
  25. Errno2InoutRes:=217;
  26. __WASI_ERRNO_INVAL:
  27. Errno2InoutRes:=218;
  28. __WASI_ERRNO_PIPE,
  29. __WASI_ERRNO_INTR,
  30. __WASI_ERRNO_IO,
  31. __WASI_ERRNO_AGAIN,
  32. __WASI_ERRNO_NOSPC:
  33. Errno2InoutRes:=101;
  34. __WASI_ERRNO_NAMETOOLONG:
  35. Errno2InoutRes:=3;
  36. __WASI_ERRNO_ROFS,
  37. __WASI_ERRNO_EXIST,
  38. __WASI_ERRNO_NOTEMPTY,
  39. __WASI_ERRNO_ACCES:
  40. Errno2InoutRes:=5;
  41. __WASI_ERRNO_BUSY,
  42. __WASI_ERRNO_NOTDIR, // busy, enotdir, mantis #25931
  43. __WASI_ERRNO_ISDIR:
  44. Errno2InoutRes:=5;
  45. else
  46. Errno2InoutRes:=errno;
  47. end;
  48. end;
  49. {*****************************************************************************
  50. Low Level File Routines
  51. *****************************************************************************}
  52. function Do_IsDevice(Handle:THandle):boolean;
  53. var
  54. res: __wasi_errno_t;
  55. ourfdstat: __wasi_fdstat_t;
  56. begin
  57. res:=__wasi_fd_fdstat_get(Handle,@ourfdstat);
  58. if res=__WASI_ERRNO_SUCCESS then
  59. begin
  60. if ourfdstat.fs_filetype=__WASI_FILETYPE_UNKNOWN then
  61. { wasmtime 0.24.0 and later versions return __WASI_FILETYPE_UNKNOWN for stdin/stdout/stderr }
  62. Do_IsDevice:=Handle<=2
  63. else
  64. Do_IsDevice:=ourfdstat.fs_filetype in [__WASI_FILETYPE_BLOCK_DEVICE,__WASI_FILETYPE_CHARACTER_DEVICE]
  65. end
  66. else
  67. { in case of error (e.g. access denied), assume device for stdin/stdout/stderr }
  68. Do_IsDevice:=Handle<=2;
  69. end;