sysos.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. var
  14. initialstkptr: pointer; public name '__stkptr';
  15. operatingsystem_parameter_envp: ppchar; public name 'operatingsystem_parameter_envp';
  16. operatingsystem_parameter_argc: ptruint; public name 'operatingsystem_parameter_argc';
  17. operatingsystem_parameter_argv: ppchar; public name 'operatingsystem_parameter_argv';
  18. const clib = 'c';
  19. type libcint=longint;
  20. plibcint=^libcint;
  21. function geterrnolocation: Plibcint; cdecl;external stdclib name 'getThdErrno';
  22. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  23. begin
  24. geterrno:=geterrnolocation^;
  25. end;
  26. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  27. begin
  28. geterrnolocation^:=err;
  29. end;
  30. { OS dependant parts }
  31. {$I errno.inc} // error numbers
  32. {$I ostypes.inc} // c-types, unix base types, unix base structures
  33. {$I osmacro.inc}
  34. {$i oscdeclh.inc}
  35. {$i oscdecl.inc}
  36. // used in sysheap.inc
  37. function FpMalloc(size: size_t): pointer; cdecl; external clib name 'malloc';
  38. procedure FpFree(p: pointer); cdecl; external clib name 'free';
  39. {*****************************************************************************
  40. Error conversion
  41. *****************************************************************************}
  42. {
  43. The lowlevel file functions should take care of setting the InOutRes to the
  44. correct value if an error has occured, else leave it untouched
  45. }
  46. Function PosixToRunError (PosixErrno : longint) : longint;
  47. {
  48. Convert ErrNo error to the correct Inoutres value
  49. }
  50. begin
  51. if PosixErrNo=0 then { Else it will go through all the cases }
  52. exit(0);
  53. case PosixErrNo of
  54. ESysENFILE,
  55. ESysEMFILE : Inoutres:=4;
  56. ESysENOENT : Inoutres:=2;
  57. ESysEBADF : Inoutres:=6;
  58. ESysENOMEM,
  59. ESysEFAULT : Inoutres:=217;
  60. ESysEINVAL : Inoutres:=218;
  61. ESysEPIPE,
  62. ESysEINTR,
  63. ESysEIO,
  64. ESysEAGAIN,
  65. ESysENOSPC : Inoutres:=101;
  66. ESysENAMETOOLONG : Inoutres := 3;
  67. ESysEROFS,
  68. ESysEEXIST,
  69. ESysENOTEMPTY,
  70. ESysEACCES : Inoutres:=5;
  71. ESysEISDIR : InOutRes:=5;
  72. else
  73. begin
  74. InOutRes := Integer(PosixErrno);
  75. end;
  76. end;
  77. PosixToRunError:=InOutRes;
  78. end;
  79. Function Errno2InoutRes : longint;
  80. begin
  81. Errno2InoutRes:=PosixToRunError(getErrno);
  82. InoutRes:=Errno2InoutRes;
  83. end;
  84. {*****************************************************************************
  85. Low Level File Routines
  86. *****************************************************************************}
  87. Function Do_IsDevice(Handle:Longint):boolean;
  88. {
  89. Interface to Unix ioctl call.
  90. Performs various operations on the filedescriptor Handle.
  91. Ndx describes the operation to perform.
  92. Data points to data needed for the Ndx function. The structure of this
  93. data is function-dependent.
  94. }
  95. CONST
  96. IOCtl_TCGETS=$40000000+$2C7400+ 19;
  97. var
  98. Data : array[0..255] of byte; {Large enough for termios info}
  99. begin
  100. Do_IsDevice:=(Fpioctl(handle,IOCTL_TCGETS,@data)<>-1);
  101. end;