0002-Extract-a-function-for-splitting-a-colon-separated-s.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From a8452dc7e80eb17572c7458e33a4f4d609e6a3da Mon Sep 17 00:00:00 2001
  2. From: Tuomas Tynkkynen <tuomas@tuxera.com>
  3. Date: Fri, 3 Jun 2016 23:03:51 +0300
  4. Subject: [PATCH] Extract a function for splitting a colon-separated string
  5. We're going to need this logic in another place, so make a function of
  6. this.
  7. [Upstream-commit: https://github.com/NixOS/patchelf/commit/2e3fdc2030c75c19df6fc2924083cfad53856562]
  8. Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
  9. ---
  10. src/patchelf.cc | 28 +++++++++++++++++++---------
  11. 1 file changed, 19 insertions(+), 9 deletions(-)
  12. diff --git a/src/patchelf.cc b/src/patchelf.cc
  13. index c870638..1d9a772 100644
  14. --- a/src/patchelf.cc
  15. +++ b/src/patchelf.cc
  16. @@ -57,6 +57,22 @@ unsigned char * contents = 0;
  17. #define ElfFileParamNames Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym
  18. +static vector<string> splitColonDelimitedString(const char * s){
  19. + vector<string> parts;
  20. + const char * pos = s;
  21. + while (*pos) {
  22. + const char * end = strchr(pos, ':');
  23. + if (!end) end = strchr(pos, 0);
  24. +
  25. + parts.push_back(string(pos, end - pos));
  26. + if (*end == ':') ++end;
  27. + pos = end;
  28. + }
  29. +
  30. + return parts;
  31. +}
  32. +
  33. +
  34. static unsigned int getPageSize(){
  35. return pageSize;
  36. }
  37. @@ -1093,15 +1109,9 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath)
  38. newRPath = "";
  39. - char * pos = rpath;
  40. - while (*pos) {
  41. - char * end = strchr(pos, ':');
  42. - if (!end) end = strchr(pos, 0);
  43. -
  44. - /* Get the name of the directory. */
  45. - string dirName(pos, end - pos);
  46. - if (*end == ':') ++end;
  47. - pos = end;
  48. + vector<string> rpathDirs = splitColonDelimitedString(rpath);
  49. + for (vector<string>::iterator it = rpathDirs.begin(); it != rpathDirs.end(); ++it) {
  50. + const string & dirName = *it;
  51. /* Non-absolute entries are allowed (e.g., the special
  52. "$ORIGIN" hack). */
  53. --
  54. 1.9.1