dynlibs.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Implement OS-dependent part of dynamic library loading.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. uses dl;
  12. Function SysLoadLibraryA(const Name : RawByteString) : TLibHandle;
  13. {$ifdef aix}
  14. var
  15. MemberName: RawByteString;
  16. {$endif}
  17. begin
  18. {$ifndef aix}
  19. Result:=TLibHandle(dlopen(PAnsiChar(Name),RTLD_LAZY));
  20. {$else aix}
  21. { in aix, most shared libraries are static libraries (archives) that contain
  22. a single object: shr.o for 32 bit, shr_64.o for 64 bit. You have to specify
  23. this object file explicitly via the RTLD_MEMBER member flag }
  24. {$ifdef cpu64}
  25. MemberName:='(shr_64.o)';
  26. {$else cpu64}
  27. MemberName:='(shr.o)';
  28. {$endif cpu64}
  29. SetCodePage(MemberName,DefaultFileSystemCodePage,false);
  30. MemberName:=Name+MemberName;
  31. Result:=TLibHandle(dlopen(PAnsiChar(MemberName),RTLD_LAZY or RTLD_MEMBER));
  32. {$endif aix}
  33. end;
  34. Function SysLoadLibraryU(const Name: UnicodeString) : TLibHandle;
  35. begin
  36. Result := SysLoadLibraryA(ToSingleByteFileSystemEncodedFileName(Name));
  37. end;
  38. Function SysGetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  39. begin
  40. Result:=dlsym(lib,pchar(ProcName));
  41. end;
  42. Function SysUnloadLibrary(Lib : TLibHandle) : Boolean;
  43. begin
  44. Result:=dlClose(Lib)=0;
  45. end;
  46. Function SysGetLoadErrorStr: string;
  47. begin
  48. Result:=dl.dlerror;
  49. end;
  50. const
  51. SysDynLibsManager: TDynLibsManager = (
  52. LoadLibraryU: @SysLoadLibraryU;
  53. LoadLibraryA: @SysLoadLibraryA;
  54. GetProcAddress: @SysGetProcedureAddress;
  55. GetProcAddressOrdinal: Nil;
  56. UnloadLibrary: @SysUnloadLibrary;
  57. GetLoadErrorStr: @SysGetLoadErrorStr;
  58. );
  59. procedure InitDynLibs;
  60. begin
  61. SetDynLibsManager(SysDynLibsManager);
  62. end;