dlafk.c 757 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <dlfcn.h>
  5. #include <stdint.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #define LIBNAME "libafk.so"
  10. #define LIBAFK "libafk-temp.so"
  11. #define LIBAFK_BAK ".libafk-temp.so.temp"
  12. int main(int argc, char **argv)
  13. {
  14. void *handle;
  15. if (rename(LIBAFK, LIBAFK_BAK)) {
  16. fprintf(stderr, "Unable to rename %s: %s\n", LIBAFK, strerror(errno));
  17. return EXIT_FAILURE;
  18. }
  19. handle = dlopen(LIBNAME, RTLD_NOW);
  20. if (!handle) {
  21. fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
  22. return EXIT_FAILURE;
  23. }
  24. if (rename(LIBAFK_BAK, LIBAFK)) {
  25. fprintf(stderr, "Unable to rename %s: %s\n", LIBAFK_BAK, strerror(errno));
  26. return EXIT_FAILURE;
  27. }
  28. return EXIT_SUCCESS;
  29. }