sysos.inc 3.4 KB

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