sysos.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. function geterrnolocation: Plibcint; cdecl;external clib name'__errno_location';
  19. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  20. begin
  21. geterrno:=geterrnolocation^;
  22. end;
  23. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  24. begin
  25. geterrnolocation^:=err;
  26. end;
  27. {$else}
  28. {$ifdef ver1_0}
  29. Var
  30. {$else}
  31. ThreadVar
  32. {$endif}
  33. Errno : longint;
  34. function geterrno:longint; [public, alias: 'FPC_SYS_GETERRNO'];
  35. begin
  36. GetErrno:=Errno;
  37. end;
  38. procedure seterrno(err:longint); [public, alias: 'FPC_SYS_SETERRNO'];
  39. begin
  40. Errno:=err;
  41. end;
  42. {$endif}
  43. { OS dependant parts }
  44. {$I errno.inc} // error numbers
  45. {$I ostypes.inc} // c-types, unix base types, unix base structures
  46. {$I osmacro.inc}
  47. {$ifdef FPC_USE_LIBC}
  48. {$Linklib c}
  49. {$i oscdeclh.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. else
  90. begin
  91. InOutRes := Integer(PosixErrno);
  92. end;
  93. end;
  94. PosixToRunError:=InOutRes;
  95. end;
  96. Function Errno2InoutRes : longint;
  97. begin
  98. Errno2InoutRes:=PosixToRunError(getErrno);
  99. InoutRes:=Errno2InoutRes;
  100. end;
  101. {*****************************************************************************
  102. Low Level File Routines
  103. *****************************************************************************}
  104. Function Do_IsDevice(Handle:THandle):boolean;
  105. {
  106. Interface to Unix ioctl call.
  107. Performs various operations on the filedescriptor Handle.
  108. Ndx describes the operation to perform.
  109. Data points to data needed for the Ndx function. The structure of this
  110. data is function-dependent.
  111. }
  112. const
  113. {$ifdef PowerPC}
  114. IOCtl_TCGETS=$402c7413;
  115. {$else}
  116. IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
  117. {$endif}
  118. var
  119. Data : array[0..255] of byte; {Large enough for termios info}
  120. begin
  121. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  122. end;
  123. {
  124. $Log$
  125. Revision 1.5 2005-02-13 21:47:56 peter
  126. * include file cleanup part 2
  127. Revision 1.4 2005/02/13 20:01:38 peter
  128. * include file cleanup
  129. Revision 1.3 2005/02/07 22:04:55 peter
  130. * moved to unix
  131. Revision 1.2 2005/02/06 13:06:20 peter
  132. * moved file and dir functions to sysfile/sysdir
  133. * win32 thread in systemunit
  134. Revision 1.1 2005/02/06 11:20:52 peter
  135. * threading in system unit
  136. * removed systhrds unit
  137. }