sysos.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by Free Pascal development team
  5. This file implements all the base types and limits required
  6. for a minimal POSIX compliant subset required to port the compiler
  7. to a new OS.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. {$ifdef FPC_USE_LIBC}
  15. const clib = 'c';
  16. type libcint=longint;
  17. plibcint=^libcint;
  18. {$ifdef FreeBSD} // tested on x86
  19. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  20. {$else}
  21. {$ifdef NetBSD} // from a sparc dump.
  22. function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
  23. {$else}
  24. {$ifdef Darwin}
  25. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  26. {$else}
  27. {$ifdef OpenBSD}
  28. var libcerrno : libcint; cvar;
  29. function geterrnolocation: Plibcint; cdecl;
  30. begin
  31. geterrnolocation:=@libcerrno;
  32. end;
  33. {$else}
  34. {$endif}
  35. {$endif}
  36. {$endif}
  37. {$endif}
  38. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  39. begin
  40. geterrno:=geterrnolocation^;
  41. end;
  42. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  43. begin
  44. geterrnolocation^:=err;
  45. end;
  46. {$else}
  47. {$ifdef ver1_0}
  48. Var
  49. {$else}
  50. threadvar
  51. {$endif}
  52. Errno : longint;
  53. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  54. begin
  55. GetErrno:=Errno;
  56. end;
  57. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  58. begin
  59. Errno:=err;
  60. end;
  61. {$endif}
  62. { OS dependant parts }
  63. {$I errno.inc} // error numbers
  64. {$I ostypes.inc} // c-types, unix base types, unix base structures
  65. {$I osmacro.inc}
  66. {$ifdef FPC_USE_LIBC}
  67. {$Linklib c}
  68. {$i oscdeclh.inc}
  69. {$else}
  70. {$I syscallh.inc}
  71. {$I syscall.inc}
  72. {$I sysnr.inc}
  73. {$I ossysc.inc}
  74. {$endif}
  75. {*****************************************************************************
  76. Error conversion
  77. *****************************************************************************}
  78. {
  79. The lowlevel file functions should take care of setting the InOutRes to the
  80. correct value if an error has occured, else leave it untouched
  81. }
  82. Function PosixToRunError (PosixErrno : longint) : longint;
  83. {
  84. Convert ErrNo error to the correct Inoutres value
  85. }
  86. begin
  87. if PosixErrNo=0 then { Else it will go through all the cases }
  88. exit(0);
  89. case PosixErrNo of
  90. ESysENFILE,
  91. ESysEMFILE : Inoutres:=4;
  92. ESysENOENT : Inoutres:=2;
  93. ESysEBADF : Inoutres:=6;
  94. ESysENOMEM,
  95. ESysEFAULT : Inoutres:=217;
  96. ESysEINVAL : Inoutres:=218;
  97. ESysEPIPE,
  98. ESysEINTR,
  99. ESysEIO,
  100. ESysEAGAIN,
  101. ESysENOSPC : Inoutres:=101;
  102. ESysENAMETOOLONG : Inoutres := 3;
  103. ESysEROFS,
  104. ESysEEXIST,
  105. ESysENOTEMPTY,
  106. ESysEACCES : Inoutres:=5;
  107. ESysEISDIR : InOutRes:=5;
  108. else
  109. begin
  110. InOutRes := Integer(PosixErrno);
  111. end;
  112. end;
  113. PosixToRunError:=InOutRes;
  114. end;
  115. Function Errno2InoutRes : longint;
  116. begin
  117. Errno2InoutRes:=PosixToRunError(getErrno);
  118. InoutRes:=Errno2InoutRes;
  119. end;
  120. {*****************************************************************************
  121. Low Level File Routines
  122. *****************************************************************************}
  123. Function Do_IsDevice(Handle:Longint):boolean;
  124. {
  125. Interface to Unix ioctl call.
  126. Performs various operations on the filedescriptor Handle.
  127. Ndx describes the operation to perform.
  128. Data points to data needed for the Ndx function. The structure of this
  129. data is function-dependent.
  130. }
  131. CONST
  132. IOCtl_TCGETS=$5401;
  133. var
  134. Data : array[0..255] of byte; {Large enough for termios info}
  135. begin
  136. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  137. end;
  138. {
  139. $Log$
  140. Revision 1.4 2005-02-13 21:47:56 peter
  141. * include file cleanup part 2
  142. Revision 1.3 2005/02/07 22:04:55 peter
  143. * moved to unix
  144. Revision 1.2 2005/02/06 13:06:20 peter
  145. * moved file and dir functions to sysfile/sysdir
  146. * win32 thread in systemunit
  147. Revision 1.1 2005/02/06 12:16:52 peter
  148. * bsd thread updates
  149. }