sysos.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ESysEBusy,
  59. ESysENOTDIR, // busy, enotdir, mantis #25931
  60. ESysEACCES : Inoutres:=5;
  61. ESysEISDIR : InOutRes:=5;
  62. else
  63. begin
  64. InOutRes := Integer(PosixErrno);
  65. end;
  66. end;
  67. PosixToRunError:=InOutRes;
  68. end;
  69. Function Errno2InoutRes : longint;
  70. begin
  71. Errno2InoutRes:=PosixToRunError(getErrno);
  72. InoutRes:=Errno2InoutRes;
  73. end;
  74. {*****************************************************************************
  75. Low Level File Routines
  76. *****************************************************************************}
  77. function do_isdevice(handle:longint):boolean;
  78. var
  79. StatRec: Stat;
  80. begin
  81. fpFStat (Handle, StatRec);
  82. case StatRec.st_Mode and S_IFMT of
  83. S_IFCHR, S_IFIFO, S_IFSOCK: Do_IsDevice := true
  84. else
  85. Do_IsDevice := false;
  86. end;
  87. end;