initc.pp 2.0 KB

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