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