initc.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 OpenBSD also uses __errno function }
  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. {$if defined(Linux)}
  40. function geterrnolocation: pcint; cdecl;external clib name '__errno_location';
  41. {$endif}
  42. {$if defined(Android)} // look at exported symbols in libc.so
  43. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  44. {$endif}
  45. {$if defined(FreeBSD) or defined(DragonFly)} // tested on x86
  46. function geterrnolocation: pcint; cdecl;external clib name '__error';
  47. {$endif}
  48. {$ifdef OpenBSD} // tested on x86
  49. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  50. {$endif}
  51. {$ifdef NetBSD} // from a sparc dump.
  52. function geterrnolocation: pcint; cdecl;external clib name '__errno';
  53. {$endif}
  54. {$ifdef Darwin}
  55. function geterrnolocation: pcint; cdecl;external clib name '__error';
  56. {$endif}
  57. {$ifdef SunOS}
  58. function geterrnolocation: pcint; cdecl;external clib name '___errno';
  59. {$endif}
  60. {$ifdef beos}
  61. function geterrnolocation: pcint; cdecl;external 'root' name '_errnop';
  62. {$endif}
  63. {$ifdef aix}
  64. function geterrnolocation: pcint; cdecl;external clib name '_Errno';
  65. {$endif}
  66. function fpgetCerrno:cint;
  67. begin
  68. fpgetCerrno:=geterrnolocation^;
  69. end;
  70. procedure fpsetCerrno(err:cint);
  71. begin
  72. geterrnolocation^:=err;
  73. end;
  74. {$endif}
  75. end.