1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768# 1 "src/ctypes-foreign/dl.ml.unix"(*
* Copyright (c) 2013 Jeremy Yallop.
*
* This file is distributed under the terms of the MIT License.
* See the file LICENSE for details.
*)[@@@ocaml.warning"-16"]typelibrarytypeflag=RTLD_LAZY|RTLD_NOW|RTLD_GLOBAL|RTLD_LOCAL|RTLD_NODELETE|RTLD_NOLOAD|RTLD_DEEPBINDexceptionDL_errorofstring(* void *dlopen(const char *filename, int flag); *)external_dlopen:?filename:string->flags:int->libraryoption="ctypes_dlopen"(* void *dlsym(void *handle, const char *symbol); *)external_dlsym:?handle:library->symbol:string->nativeintoption="ctypes_dlsym"(* int dlclose(void *handle); *)external_dlclose:handle:library->int="ctypes_dlclose"(* char *dlerror(void); *)external_dlerror:unit->stringoption="ctypes_dlerror"externalresolve_flag:flag->int="ctypes_resolve_dl_flag"let_report_dl_errornoload=match_dlerror()with|Someerror->raise(DL_error(error))|None->ifnoloadthenraise(DL_error"library not loaded")elsefailwith"dl_error: expected error, but no error reported"letcrush_flagsf:'alist->int=List.fold_left(funio->ilor(fo))0[@@@warning"-16"]letdlopen?filename~flags=match_dlopen?filename~flags:(crush_flagsresolve_flagflags)with|Somelibrary->library|None->_report_dl_error(List.memRTLD_NOLOADflags)letdlclose~handle=match_dlclose~handlewith|0->()|_->_report_dl_errorfalseletdlsym?handle~symbol=match_dlsym?handle~symbolwith|Somesymbol->symbol|None->_report_dl_errorfalse