diff options
author | Tuomas Tynkkynen <tuomas@tuxera.com> | 2016-06-03 20:03:51 (GMT) |
---|---|---|
committer | Tuomas Tynkkynen <tuomas@tuxera.com> | 2016-06-03 20:03:51 (GMT) |
commit | 2e3fdc2030c75c19df6fc2924083cfad53856562 (patch) | |
tree | b15fe7009e1e91cd18aff5155e45a03b6d3c19c9 /src/patchelf.cc | |
parent | c66b2deb6089d29cbb7261c28282da32ea65c384 (diff) | |
download | patchelf-2e3fdc2030c75c19df6fc2924083cfad53856562.zip patchelf-2e3fdc2030c75c19df6fc2924083cfad53856562.tar.gz patchelf-2e3fdc2030c75c19df6fc2924083cfad53856562.tar.bz2 |
Extract a function for splitting a colon-separated string
We're going to need this logic in another place, so make a function of
this.
Diffstat (limited to 'src/patchelf.cc')
-rw-r--r-- | src/patchelf.cc | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/patchelf.cc b/src/patchelf.cc index ca8fb49..b4e3e18 100644 --- a/src/patchelf.cc +++ b/src/patchelf.cc @@ -57,6 +57,22 @@ unsigned char * contents = 0; #define ElfFileParamNames Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym, Elf_Verneed +static vector<string> splitColonDelimitedString(const char * s){ + vector<string> parts; + const char * pos = s; + while (*pos) { + const char * end = strchr(pos, ':'); + if (!end) end = strchr(pos, 0); + + parts.push_back(string(pos, end - pos)); + if (*end == ':') ++end; + pos = end; + } + + return parts; +} + + static unsigned int getPageSize(){ return pageSize; } @@ -1095,15 +1111,9 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath) newRPath = ""; - char * pos = rpath; - while (*pos) { - char * end = strchr(pos, ':'); - if (!end) end = strchr(pos, 0); - - /* Get the name of the directory. */ - string dirName(pos, end - pos); - if (*end == ':') ++end; - pos = end; + vector<string> rpathDirs = splitColonDelimitedString(rpath); + for (vector<string>::iterator it = rpathDirs.begin(); it != rpathDirs.end(); ++it) { + const string & dirName = *it; /* Non-absolute entries are allowed (e.g., the special "$ORIGIN" hack). */ |