initc.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman,
  5. members of the Free Pascal development team
  6. This file links to libc, and handles the libc errno abstraction.
  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. unit initc;
  14. interface
  15. {$linklib c}
  16. type libcint = longint;
  17. plibcint = ^libcint;
  18. function fpgetCerrno:libcint;
  19. procedure fpsetCerrno(err:libcint);
  20. {$ifdef HASGLOBALPROPERTY}
  21. property cerrno:libcint read fpgetCerrno write fpsetcerrno;
  22. {$endif HASGLOBALPROPERTY}
  23. const clib = 'c';
  24. implementation
  25. // hasn't been divided up in .inc's, because I first want to see hoe
  26. // this idea works out.
  27. {$ifdef OpenBSD}
  28. {$define UseOldErrnoDirectLink}
  29. {$endif}
  30. {$ifdef UseOldErrnoDirectLink}
  31. Var
  32. interrno : libcint;external name {$ifdef OpenBSD} '_errno' {$else} 'h_errno'{$endif};
  33. function fpgetCerrno:libcint;
  34. begin
  35. fpgetCerrno:=interrno;
  36. end;
  37. procedure fpsetCerrno(err:libcint);
  38. begin
  39. interrno:=err;
  40. end;
  41. {$else}
  42. {$ifdef Linux}
  43. function geterrnolocation: Plibcint; cdecl;external clib name '__errno_location';
  44. {$else}
  45. {$ifdef FreeBSD} // tested on x86
  46. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  47. {$else}
  48. {$ifdef NetBSD} // from a sparc dump.
  49. function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
  50. {$else}
  51. {$ifdef Darwin}
  52. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  53. {$endif}
  54. {$endif}
  55. {$endif}
  56. {$endif}
  57. function fpgetCerrno:libcint;
  58. begin
  59. fpgetCerrno:=geterrnolocation^;
  60. end;
  61. procedure fpsetCerrno(err:libcint);
  62. begin
  63. geterrnolocation^:=err;
  64. end;
  65. {$endif}
  66. end.
  67. {
  68. $Log$
  69. Revision 1.12 2005-02-14 17:13:31 peter
  70. * truncate log
  71. }