sysos.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. {$else}
  50. {$I syscallh.inc}
  51. {$I syscall.inc}
  52. {$I sysnr.inc}
  53. {$I ossysc.inc}
  54. {$endif}
  55. {*****************************************************************************
  56. Error conversion
  57. *****************************************************************************}
  58. {
  59. The lowlevel file functions should take care of setting the InOutRes to the
  60. correct value if an error has occured, else leave it untouched
  61. }
  62. Function PosixToRunError (PosixErrno : longint) : longint;
  63. {
  64. Convert ErrNo error to the correct Inoutres value
  65. }
  66. begin
  67. if PosixErrNo=0 then { Else it will go through all the cases }
  68. exit(0);
  69. case PosixErrNo of
  70. ESysENFILE,
  71. ESysEMFILE : Inoutres:=4;
  72. ESysENOENT : Inoutres:=2;
  73. ESysEBADF : Inoutres:=6;
  74. ESysENOMEM,
  75. ESysEFAULT : Inoutres:=217;
  76. ESysEINVAL : Inoutres:=218;
  77. ESysEPIPE,
  78. ESysEINTR,
  79. ESysEIO,
  80. ESysEAGAIN,
  81. ESysENOSPC : Inoutres:=101;
  82. ESysENAMETOOLONG : Inoutres := 3;
  83. ESysEROFS,
  84. ESysEEXIST,
  85. ESysENOTEMPTY,
  86. ESysEACCES : Inoutres:=5;
  87. ESysEISDIR : InOutRes:=5;
  88. ESysEPERM : 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:Longint):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. IOCtl_TCGETS=$5401;
  114. var
  115. Data : array[0..255] of byte; {Large enough for termios info}
  116. begin
  117. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  118. end;