2
0

initc.pp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman,
  4. members of the Free Pascal development team
  5. This file links to libc, and handles the libc errno abstraction.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit initc;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$IFDEF FPC_DOTTEDUNITS}
  17. uses
  18. System.CTypes;
  19. {$ELSE FPC_DOTTEDUNITS}
  20. uses
  21. ctypes;
  22. {$ENDIF FPC_DOTTEDUNITS}
  23. {$linklib c}
  24. function fpgetCerrno:cint;
  25. procedure fpsetCerrno(err:cint);
  26. property cerrno:cint read fpgetCerrno write fpsetcerrno;
  27. const clib = 'c';
  28. implementation
  29. // hasn't been divided up in .inc's, because I first want to see hoe
  30. // this idea works out.
  31. {$ifdef OpenBSD}
  32. {define UseOldErrnoDirectLink OpenBSD also uses __errno function }
  33. {$endif}
  34. {$ifdef UseOldErrnoDirectLink}
  35. Var
  36. interrno : cint;external name {$ifdef OpenBSD} '_errno' {$else} 'h_errno'{$endif};
  37. function fpgetCerrno:cint;
  38. begin
  39. fpgetCerrno:=interrno;
  40. end;
  41. procedure fpsetCerrno(err:cint);
  42. begin
  43. interrno:=err;
  44. end;
  45. {$else}
  46. {$if defined(Linux)}
  47. function geterrnolocation: pcint; cdecl;external clib name '__errno_location';
  48. {$endif}
  49. {$if defined(Android)} // look at exported symbols in libc.so
  50. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  51. {$endif}
  52. {$if defined(FreeBSD) or defined(DragonFly)} // tested on x86
  53. function geterrnolocation: pcint; cdecl;external clib name '__error';
  54. {$endif}
  55. {$ifdef OpenBSD} // tested on x86
  56. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  57. {$endif}
  58. {$ifdef NetBSD} // from a sparc dump.
  59. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  60. {$endif}
  61. {$ifdef Darwin}
  62. function geterrnolocation: pcint; cdecl;external clib name '__error';
  63. {$endif}
  64. {$ifdef SunOS}
  65. function geterrnolocation: pcint; cdecl;external clib name '___errno';
  66. {$endif}
  67. {$ifdef beos}
  68. function geterrnolocation: pcint; cdecl;external 'root' name '_errnop';
  69. {$endif}
  70. {$ifdef aix}
  71. function geterrnolocation: pcint; cdecl;external clib name '_Errno';
  72. {$endif}
  73. function fpgetCerrno:cint;
  74. begin
  75. fpgetCerrno:=geterrnolocation^;
  76. end;
  77. procedure fpsetCerrno(err:cint);
  78. begin
  79. geterrnolocation^:=err;
  80. end;
  81. {$endif}
  82. end.