initc.pp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. {$ifndef ver1_0}
  21. property cerrno:libcint read fpgetCerrno write fpsetcerrno;
  22. {$endif}
  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 UseOldErrnoDirectLink}
  27. Var
  28. interrno : libcint;external name 'h_errno';
  29. function fpgetCerrno:libcint;
  30. begin
  31. fpgetCerrno:=interrno;
  32. end;
  33. procedure fpsetCerrno(err:libcint);
  34. begin
  35. interrno:=err;
  36. end;
  37. {$else}
  38. const clib = 'c';
  39. {$ifdef Linux}
  40. function geterrnolocation: Plibcint; cdecl;external clib name '__errno_location';
  41. {$else}
  42. {$ifdef FreeBSD} // tested on x86
  43. function geterrnolocation: Plibcint; cdecl;external clib name '__error';
  44. {$else}
  45. {$ifdef NetBSD} // from a sparc dump.
  46. function geterrnolocation: Plibcint; cdecl;external clib name '__errno';
  47. {$else}
  48. {$endif}
  49. {$endif}
  50. {$endif}
  51. function fpgetCerrno:libcint;
  52. begin
  53. fpgetCerrno:=geterrnolocation^;
  54. end;
  55. procedure fpsetCerrno(err:libcint);
  56. begin
  57. geterrnolocation^:=err;
  58. end;
  59. {$endif}
  60. end.
  61. {
  62. $Log$
  63. Revision 1.7 2003-12-10 17:14:27 marco
  64. * property support under ifndef ver1_0
  65. Revision 1.6 2003/12/10 17:06:19 marco
  66. * property support used.
  67. Revision 1.5 2003/12/10 14:59:49 marco
  68. * NetBSD supported added based on Sparc and define name changed to something more sensible
  69. Revision 1.4 2003/12/10 11:24:25 marco
  70. * get/setcerrno added
  71. Revision 1.3 2002/09/07 16:01:27 peter
  72. * old logs removed and tabs fixed
  73. }