| 1 | #cxx . . $ `<file>/seatac/sharedObj.H`/ifndef SHAREDOBJ_H |
| 2 | #define SHAREDOBJ_Hcxx . . $ `seatac/sharedObj.H:2:9`! |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <string.h> |
| 7 | #include <dlfcn.h> |
| 8 | #include <errno.h> |
| 9 | |
| 10 | // A wrapper around a shared object. |
| 11 | // |
| 12 | // Responsible for opening, accessing and closing a shared object. |
| 13 | // |
| 14 | |
| 15 | class sharedObjcxx . . $ sharedObj# { |
| 16 | public: |
| 17 | |
| 18 | sharedObjcxx . . $ sharedObj#sharedObj(fda57c8427c60377).(char *p) { |
| 19 | pathcxx . . $ sharedObj#path. = new char [strlen(p) + 1]; |
| 20 | strcpy(pathcxx . . $ sharedObj#path., p); |
| 21 | |
| 22 | handlecxx . . $ sharedObj#handle. = dlopen(pathcxx . . $ sharedObj#path., RTLD_NOWcxx . . $ `<external>/10632388298615623587/dlfcn.h:25:9`!); |
| 23 | if (handlecxx . . $ sharedObj#handle. == 0L) { |
| 24 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Failed to open shared object '%s'\n%s\n", pathcxx . . $ sharedObj#path., dlerror()); |
| 25 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | ~cxx . . $ sharedObj#`~sharedObj`(ced63f7c635d850d).sharedObjcxx . . $ sharedObj#() { |
| 30 | if (dlclose(handlecxx . . $ sharedObj#handle.)) { |
| 31 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: Failed to close shared object '%s'\n%s\n", pathcxx . . $ sharedObj#path., dlerror()); |
| 32 | } |
| 33 | delete [] pathcxx . . $ sharedObj#path.; |
| 34 | }; |
| 35 | |
| 36 | bool existscxx . . $ sharedObj#exists(c6b7e35ff6de5671).(char *name) { |
| 37 | void *ptr = 0L; |
| 38 | |
| 39 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 40 | ptr = dlsym(handlecxx . . $ sharedObj#handle., name); |
| 41 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) { |
| 42 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Failed to find symbol '%s' in shared object '%s'\n%s\n", name, pathcxx . . $ sharedObj#path., dlerror()); |
| 43 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 44 | } |
| 45 | |
| 46 | return(ptr != 0L); |
| 47 | } |
| 48 | |
| 49 | void *getcxx . . $ sharedObj#get(42228c1987407501).(char const *name) { |
| 50 | void *ptr = 0L; |
| 51 | |
| 52 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 53 | ptr = dlsym(handlecxx . . $ sharedObj#handle., name); |
| 54 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) { |
| 55 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Failed to find symbol '%s' in shared object '%s'\n%s\n", name, pathcxx . . $ sharedObj#path., dlerror()); |
| 56 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 57 | } |
| 58 | if (ptr == 0L) { |
| 59 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ERROR: Symbol '%s' not present in shared object '%s'\n", name, pathcxx . . $ sharedObj#path.); |
| 60 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 61 | } |
| 62 | |
| 63 | return(ptr); |
| 64 | }; |
| 65 | |
| 66 | private: |
| 67 | char *pathcxx . . $ sharedObj#path.; |
| 68 | void *handlecxx . . $ sharedObj#handle.; |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | #endif // SHAREDOBJ_H |