Skip to content

Commit 2e3fdc2

Browse files
committed
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.
1 parent c66b2de commit 2e3fdc2

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/patchelf.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ unsigned char * contents = 0;
5757
#define ElfFileParamNames Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Addr, Elf_Off, Elf_Dyn, Elf_Sym, Elf_Verneed
5858

5959

60+
static vector<string> splitColonDelimitedString(const char * s){
61+
vector<string> parts;
62+
const char * pos = s;
63+
while (*pos) {
64+
const char * end = strchr(pos, ':');
65+
if (!end) end = strchr(pos, 0);
66+
67+
parts.push_back(string(pos, end - pos));
68+
if (*end == ':') ++end;
69+
pos = end;
70+
}
71+
72+
return parts;
73+
}
74+
75+
6076
static unsigned int getPageSize(){
6177
return pageSize;
6278
}
@@ -1095,15 +1111,9 @@ void ElfFile<ElfFileParamNames>::modifyRPath(RPathOp op, string newRPath)
10951111

10961112
newRPath = "";
10971113

1098-
char * pos = rpath;
1099-
while (*pos) {
1100-
char * end = strchr(pos, ':');
1101-
if (!end) end = strchr(pos, 0);
1102-
1103-
/* Get the name of the directory. */
1104-
string dirName(pos, end - pos);
1105-
if (*end == ':') ++end;
1106-
pos = end;
1114+
vector<string> rpathDirs = splitColonDelimitedString(rpath);
1115+
for (vector<string>::iterator it = rpathDirs.begin(); it != rpathDirs.end(); ++it) {
1116+
const string & dirName = *it;
11071117

11081118
/* Non-absolute entries are allowed (e.g., the special
11091119
"$ORIGIN" hack). */

0 commit comments

Comments
 (0)