sysos.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. const clib = 'c';
  14. type libcint=longint;
  15. plibcint=^libcint;
  16. function geterrnolocation: Plibcint; cdecl;external clib name '___errno';
  17. function geterrno:libcint; [public, alias: 'FPC_SYS_GETERRNO'];
  18. begin
  19. geterrno:=geterrnolocation^;
  20. end;
  21. procedure seterrno(err:libcint); [public, alias: 'FPC_SYS_SETERRNO'];
  22. begin
  23. geterrnolocation^:=err;
  24. end;
  25. { OS dependant parts }
  26. {$I errno.inc} // error numbers
  27. {$I ostypes.inc} // c-types, unix base types, unix base structures
  28. {$I osmacro.inc}
  29. {$Linklib c}
  30. {$i oscdeclh.inc}
  31. {*****************************************************************************
  32. Error conversion
  33. *****************************************************************************}
  34. Function PosixToRunError (PosixErrno : longint) : longint;
  35. {
  36. Convert ErrNo error to the correct Inoutres value
  37. }
  38. begin
  39. if PosixErrNo=0 then { Else it will go through all the cases }
  40. exit(0);
  41. case PosixErrNo of
  42. ESysENFILE,
  43. ESysEMFILE : Inoutres:=4;
  44. ESysENOENT : Inoutres:=2;
  45. ESysEBADF : Inoutres:=6;
  46. ESysENOMEM,
  47. ESysEFAULT : Inoutres:=217;
  48. ESysEINVAL : Inoutres:=218;
  49. ESysEPIPE,
  50. ESysEINTR,
  51. ESysEIO,
  52. ESysEAGAIN,
  53. ESysENOSPC : Inoutres:=101;
  54. ESysENAMETOOLONG : Inoutres := 3;
  55. ESysEROFS,
  56. ESysEEXIST,
  57. ESysENOTEMPTY,
  58. ESysEACCES : Inoutres:=5;
  59. ESysEISDIR : InOutRes:=5;
  60. else
  61. begin
  62. InOutRes := Integer(PosixErrno);
  63. end;
  64. end;
  65. PosixToRunError:=InOutRes;
  66. end;
  67. Function Errno2InoutRes : longint;
  68. begin
  69. Errno2InoutRes:=PosixToRunError(getErrno);
  70. InoutRes:=Errno2InoutRes;
  71. end;
  72. {*****************************************************************************
  73. Low Level File Routines
  74. *****************************************************************************}
  75. function do_isdevice(handle:longint):boolean;
  76. begin
  77. do_isdevice:= (handle=StdInputHandle) or
  78. (handle=StdOutputHandle) or
  79. (handle=StdErrorHandle);
  80. end;