initc.pp 2.1 KB

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