dynlibs.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2004 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 libc;
  12. Function SysLoadLibraryA(const Name : RawByteString) : TLibHandle;
  13. begin
  14. Result:=dlopen(PAnsiChar(Name),RTLD_LAZY);
  15. end;
  16. Function SysLoadLibraryU(const Name: UnicodeString) : TLibHandle;
  17. begin
  18. Result:=SysLoadLibraryA(ToSingleByteFileSystemEncodedFileName(Name));
  19. end;
  20. Function SysGetProcedureAddress(Lib : TLibHandle; const ProcName : AnsiString) : Pointer;
  21. begin
  22. Result:=dlsym(lib,pchar(ProcName));
  23. end;
  24. Function SysUnloadLibrary(Lib : TLibHandle) : Boolean;
  25. begin
  26. Result:=dlClose(Lib)=0;
  27. end;
  28. Function SysGetLoadErrorStr: string;
  29. begin
  30. Result:='';
  31. end;
  32. const
  33. SysDynLibsManager: TDynLibsManager = (
  34. LoadLibraryU: @SysLoadLibraryU;
  35. LoadLibraryA: @SysLoadLibraryA;
  36. GetProcAddress: @SysGetProcedureAddress;
  37. GetProcAddressOrdinal: Nil;
  38. UnloadLibrary: @SysUnloadLibrary;
  39. GetLoadErrorStr: @SysGetLoadErrorStr;
  40. );
  41. procedure InitDynLibs;
  42. begin
  43. SetDynLibsManager(SysDynLibsManager);
  44. end;