sysos.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. {$i oscdecl.inc}
  32. {*****************************************************************************
  33. Error conversion
  34. *****************************************************************************}
  35. Function PosixToRunError (PosixErrno : longint) : longint;
  36. {
  37. Convert ErrNo error to the correct Inoutres value
  38. }
  39. begin
  40. if PosixErrNo=0 then { Else it will go through all the cases }
  41. exit(0);
  42. case PosixErrNo of
  43. ESysENFILE,
  44. ESysEMFILE : Inoutres:=4;
  45. ESysENOENT : Inoutres:=2;
  46. ESysEBADF : Inoutres:=6;
  47. ESysENOMEM,
  48. ESysEFAULT : Inoutres:=217;
  49. ESysEINVAL : Inoutres:=218;
  50. ESysEPIPE,
  51. ESysEINTR,
  52. ESysEIO,
  53. ESysEAGAIN,
  54. ESysENOSPC : Inoutres:=101;
  55. ESysENAMETOOLONG : Inoutres := 3;
  56. ESysEROFS,
  57. ESysEEXIST,
  58. ESysENOTEMPTY,
  59. ESysEACCES : Inoutres:=5;
  60. ESysEISDIR : InOutRes:=5;
  61. else
  62. begin
  63. InOutRes := Integer(PosixErrno);
  64. end;
  65. end;
  66. PosixToRunError:=InOutRes;
  67. end;
  68. Function Errno2InoutRes : longint;
  69. begin
  70. Errno2InoutRes:=PosixToRunError(getErrno);
  71. InoutRes:=Errno2InoutRes;
  72. end;
  73. {*****************************************************************************
  74. Low Level File Routines
  75. *****************************************************************************}
  76. function do_isdevice(handle:longint):boolean;
  77. begin
  78. do_isdevice:= (handle=StdInputHandle) or
  79. (handle=StdOutputHandle) or
  80. (handle=StdErrorHandle);
  81. end;