2
0

sysos.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 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. {$ifndef FPC_USE_LIBC}
  14. {$error There's no support on Haiku for building without libc/libroot}
  15. {$endif}
  16. const
  17. clib = 'root';
  18. type libcint=longint;
  19. plibcint=^libcint;
  20. function geterrnolocation: Plibcint; cdecl;external clib name '_errnop';
  21. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  22. begin
  23. geterrno:=geterrnolocation^;
  24. end;
  25. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  26. begin
  27. geterrnolocation^:=err;
  28. end;
  29. { OS dependant parts }
  30. {$I errno.inc} // error numbers
  31. {$I ostypes.inc} // c-types, unix base types, unix base structures
  32. {$I osmacro.inc}
  33. {$i oscdeclh.inc}
  34. {$i oscdecl.inc}
  35. {*****************************************************************************
  36. Error conversion
  37. *****************************************************************************}
  38. {
  39. The lowlevel file functions should take care of setting the InOutRes to the
  40. correct value if an error has occurred, else leave it untouched
  41. }
  42. Function PosixToRunError (PosixErrno : longint) : longint;
  43. {
  44. Convert ErrNo error to the correct Inoutres value
  45. }
  46. begin
  47. if PosixErrNo=0 then { Else it will go through all the cases }
  48. exit(0);
  49. case PosixErrNo of
  50. ESysENFILE,
  51. ESysEMFILE : Inoutres:=4;
  52. ESysENOENT : Inoutres:=2;
  53. ESysEBADF : Inoutres:=6;
  54. ESysENOMEM,
  55. ESysEFAULT : Inoutres:=217;
  56. ESysEINVAL : Inoutres:=218;
  57. ESysEPIPE,
  58. ESysEINTR,
  59. ESysEIO,
  60. ESysEAGAIN,
  61. ESysENOSPC : Inoutres:=101;
  62. ESysENAMETOOLONG : Inoutres := 3;
  63. ESysEROFS,
  64. ESysEEXIST,
  65. ESysENOTEMPTY,
  66. ESysEBusy,
  67. ESysENOTDIR, // busy, enotdir, mantis #25931
  68. ESysEACCES : Inoutres:=5;
  69. ESysEISDIR : InOutRes:=5;
  70. ESysEPERM : InOutRes:=5;
  71. else
  72. begin
  73. InOutRes := Integer(PosixErrno);
  74. end;
  75. end;
  76. PosixToRunError:=InOutRes;
  77. end;
  78. Function Errno2InoutRes : longint;
  79. begin
  80. Errno2InoutRes:=PosixToRunError(getErrno);
  81. InoutRes:=Errno2InoutRes;
  82. end;
  83. {*****************************************************************************
  84. Low Level File Routines
  85. *****************************************************************************}
  86. Function Do_IsDevice(Handle:Longint):boolean;
  87. {
  88. Interface to Unix ioctl call.
  89. Performs various operations on the filedescriptor Handle.
  90. Ndx describes the operation to perform.
  91. Data points to data needed for the Ndx function. The structure of this
  92. data is function-dependent.
  93. }
  94. begin
  95. do_isdevice:= (handle=StdInputHandle) or
  96. (handle=StdOutputHandle) or
  97. (handle=StdErrorHandle);
  98. end;