initc.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. unit initc;
  13. interface
  14. uses
  15. ctypes;
  16. {$ifndef Symobi}
  17. {$linklib c}
  18. {$endif}
  19. function fpgetCerrno:cint;
  20. procedure fpsetCerrno(err:cint);
  21. property cerrno:cint read fpgetCerrno write fpsetcerrno;
  22. const clib = 'c';
  23. implementation
  24. // hasn't been divided up in .inc's, because I first want to see hoe
  25. // this idea works out.
  26. {$ifdef OpenBSD}
  27. {$define UseOldErrnoDirectLink}
  28. {$endif}
  29. {$ifdef UseOldErrnoDirectLink}
  30. Var
  31. interrno : cint;external name {$ifdef OpenBSD} '_errno' {$else} 'h_errno'{$endif};
  32. function fpgetCerrno:cint;
  33. begin
  34. fpgetCerrno:=interrno;
  35. end;
  36. procedure fpsetCerrno(err:cint);
  37. begin
  38. interrno:=err;
  39. end;
  40. {$else}
  41. {$ifdef Linux}
  42. function geterrnolocation: pcint; cdecl;external clib name '__errno_location';
  43. {$endif}
  44. {$ifdef FreeBSD} // tested on x86
  45. function geterrnolocation: pcint; cdecl;external clib name '__error';
  46. {$endif}
  47. {$ifdef NetBSD} // from a sparc dump.
  48. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  49. {$endif}
  50. {$ifdef Darwin}
  51. function geterrnolocation: pcint; cdecl;external clib name '__error';
  52. {$endif}
  53. {$ifdef SunOS}
  54. function geterrnolocation: pcint; cdecl;external clib name '___errno';
  55. {$endif}
  56. {$ifdef beos}
  57. function geterrnolocation: pcint; cdecl;external 'root' name '_errnop';
  58. {$endif}
  59. {$ifdef Symobi}
  60. function geterrnolocation: pcint; cdecl;external clib name 'getThdErrno';
  61. {$endif}
  62. function fpgetCerrno:cint;
  63. begin
  64. fpgetCerrno:=geterrnolocation^;
  65. end;
  66. procedure fpsetCerrno(err:cint);
  67. begin
  68. geterrnolocation^:=err;
  69. end;
  70. {$endif}
  71. end.