/* LSB wrapper helpers The header file contains helpers for LSB wrappers generation. */ #ifndef __LSB_HELPERS_H #define __LSB_HELPERS_H #include #include #include /* Library dlopen helpers. lib_id is an identifier to refer to this library and lib_soname is a string with sonema to dlopen. */ #define LSB_LIB_LOAD(lib_id, lib_soname) \ void * lib_id##_h; \ int lib_id##_h_tried = 0; \ char lib_id##_name[] = lib_soname; \ int lib_id##_available() \ { \ if (!lib_id##_h_tried){ \ lib_id##_h = dlopen(lib_soname,RTLD_LAZY | RTLD_GLOBAL); \ lib_id##_h_tried = 1; \ return (int)(lib_id##_h); \ }else{ \ return (int)(lib_id##_h); \ } \ } \ void* lib_id##_handle() \ { \ if (! lib_id##_available()){ \ fprintf(stderr,"Required library %s is absent in your system. LSB does not require it to present, but the program can't run without it. Sorry.\n",lib_soname); \ exit(-1); \ } \ return lib_id##_h; \ } \ // availablilty declaration for lsb_config.h #define LSB_AVAIL_RUNTIME(something) extern int something##_available(); // f - name of funciton defined in some other place // lib - id of library as supplied in LSB_LIB_LOAD #define LSB_CHECKER(lib,f) \ __typeof__(f) * f##_a; \ char const* f##_lib_name = lib##_name; \ int f##_a_tried = 0; \ int f##_available() \ { \ if (f##_a_tried){ \ return (int)f##_a; \ }else{ \ if (!lib##_available()){ \ return 0; \ } \ *(void **) (&f##_a)=dlsym(lib##_handle(), #f); \ f##_a_tried = 1; \ return (int)f##_a; \ } \ } /* Unfortunately, there is no way to predefine a macro for automatic wrapper generation. So you're just to copy it from the header file and use the LSB_WRAPPER_CALL macro, like that: int function(int arg1, void* arg2) { LSB_WRAPPER_CALL(library_id,function,arg1,arg2); } */ #define LSB_WRAPPER_CALL(f, ...) \ if (!f##_available()) \ { \ fprintf(stderr,"Required interface %s is absent in your system's library %s. LSB does not require it to present, but the program can't run without it. Sorry.\n",#f,f##_lib_name); \ exit(-1); \ } \ return (*f##_a)(__VA_ARGS__) /* Special handle for symbols that are dlsym'ed from RTLD_DEFAULT. Such symbols should be assigned to DEFAULT library */ extern char DEFAULT_name[]; extern int DEFAULT_available(); extern void* DEFAULT_handle(); #endif //include sentry