2
0

sysos.inc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 clib name'__errno_location';
  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']; register;
  23. begin
  24. geterrnolocation^:=err;
  25. end;
  26. {$else}
  27. ThreadVar
  28. Errno : longint;
  29. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  30. begin
  31. GetErrno:=Errno;
  32. end;
  33. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  34. begin
  35. Errno:=err;
  36. end;
  37. {$endif}
  38. { OS dependant parts }
  39. {$I errno.inc} // error numbers
  40. {$I ostypes.inc} // c-types, unix base types, unix base structures
  41. {$ifdef FPC_USE_LIBC}
  42. {$Linklib c}
  43. {$i oscdeclh.inc}
  44. {$i oscdecl.inc}
  45. {$else}
  46. {$I syscallh.inc}
  47. {$I syscall.inc}
  48. {$I sysnr.inc}
  49. {$I ossysc.inc}
  50. {$endif}
  51. {$I osmacro.inc}
  52. {*****************************************************************************
  53. Error conversion
  54. *****************************************************************************}
  55. {
  56. The lowlevel file functions should take care of setting the InOutRes to the
  57. correct value if an error has occured, else leave it untouched
  58. }
  59. function PosixToRunError (PosixErrno : longint):word;
  60. {
  61. Convert ErrNo error to the correct Inoutres value
  62. }
  63. var r:word; {Inoutres is declared as word.}
  64. begin
  65. (*
  66. if PosixErrNo=0 then {Else it will go through all the cases}
  67. exit(0);
  68. Statement commented out. It will not go through all the cases. (DM)
  69. *)
  70. case PosixErrNo of
  71. ESysENFILE,
  72. ESysEMFILE: r:=4;
  73. ESysENOENT: r:=2;
  74. ESysEBADF: r:=6;
  75. ESysENOMEM,
  76. ESysEFAULT: r:=217;
  77. ESysEINVAL: r:=218;
  78. ESysEPIPE,
  79. ESysEINTR,
  80. ESysEIO,
  81. ESysEAGAIN,
  82. ESysENOSPC: r:=101;
  83. ESysENAMETOOLONG: r:=3;
  84. ESysEROFS,
  85. ESysEEXIST,
  86. ESysENOTEMPTY,
  87. ESysEACCES: r:=5;
  88. ESysEISDIR: r:=5;
  89. else
  90. r:=PosixErrno;
  91. end;
  92. inoutres:=r;
  93. PosixToRunError:=r;
  94. end;
  95. function Errno2InoutRes : word;
  96. begin
  97. Errno2InoutRes:=PosixToRunError(getErrno);
  98. InoutRes:=Errno2InoutRes;
  99. end;
  100. {*****************************************************************************
  101. Low Level File Routines
  102. *****************************************************************************}
  103. Function Do_IsDevice(Handle:THandle):boolean;
  104. {
  105. Interface to Unix ioctl call.
  106. Performs various operations on the filedescriptor Handle.
  107. Ndx describes the operation to perform.
  108. Data points to data needed for the Ndx function. The structure of this
  109. data is function-dependent.
  110. }
  111. const
  112. {$if defined(PowerPC) or defined(PowerPc64)}
  113. IOCtl_TCGETS=$402c7413;
  114. {$else}
  115. {$if defined(sparc)}
  116. IOCtl_TCGETS=$40245408;
  117. {$else}
  118. IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
  119. {$endif}
  120. {$endif}
  121. var
  122. Data : array[0..255] of byte; {Large enough for termios info}
  123. begin
  124. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  125. end;