2
0

basename.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
  2. index e83621b..8aa555a 100644
  3. --- a/libkmod/libkmod-config.c
  4. +++ b/libkmod/libkmod-config.c
  5. @@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx,
  6. bool is_single = false;
  7. if (name == NULL) {
  8. - name = basename(path);
  9. + name = gnu_basename(path);
  10. is_single = true;
  11. }
  12. diff --git a/shared/util.c b/shared/util.c
  13. index e2bab83..0e16670 100644
  14. --- a/shared/util.c
  15. +++ b/shared/util.c
  16. @@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *
  17. char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len)
  18. {
  19. - char *modname;
  20. + const char *modname;
  21. - modname = basename(path);
  22. + modname = gnu_basename(path);
  23. if (modname == NULL || modname[0] == '\0')
  24. return NULL;
  25. diff --git a/shared/util.h b/shared/util.h
  26. index c4a3916..073dc5a 100644
  27. --- a/shared/util.h
  28. +++ b/shared/util.h
  29. @@ -5,6 +5,7 @@
  30. #include <stdbool.h>
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. +#include <string.h>
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36. #include <time.h>
  37. @@ -76,6 +77,12 @@ do { \
  38. __p->__v = (val); \
  39. } while(0)
  40. +static _always_inline_ const char *gnu_basename(const char *s)
  41. +{
  42. + const char *p = strrchr(s, '/');
  43. + return p ? p+1 : s;
  44. +}
  45. +
  46. static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
  47. {
  48. return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1));