summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Freeman (saurik) <saurik@saurik.com>2015-09-27 03:35:27 -0700
committerJay Freeman (saurik) <saurik@saurik.com>2015-09-27 03:35:27 -0700
commit34f4c1d83e1746db11f245349b3131180348d04c (patch)
tree4a9f16a0c532352a1ed70172cf650e27acf8467a
parent8762082fa68f4d4b9d4005065a074cc3cfc7e8b8 (diff)
downloadldid-34f4c1d83e1746db11f245349b3131180348d04c.tar.gz
ldid-34f4c1d83e1746db11f245349b3131180348d04c.tar.zst
ldid-34f4c1d83e1746db11f245349b3131180348d04c.zip
Simplify implementation of temporary reallocation.
-rw-r--r--ldid.cpp25
1 files changed, 11 insertions, 14 deletions
diff --git a/ldid.cpp b/ldid.cpp
index 12e31ed..39f2307 100644
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -1564,7 +1564,6 @@ int main(int argc, char *argv[]) {
size_t filei(0), filee(0);
_foreach (file, files) try {
const char *path(file.c_str());
- std::string temp;
if (flag_S || flag_r) {
Map input(path, O_RDONLY, PROT_READ, MAP_PRIVATE);
@@ -1577,7 +1576,7 @@ int main(int argc, char *argv[]) {
else
base = path;
- temp = dir + "." + base + ".cs";
+ std::string temp(dir + "." + base + ".cs");
std::filebuf output;
_assert(output.open(temp.c_str(), std::ios::out | std::ios::trunc | std::ios::binary) == &output);
@@ -1587,9 +1586,18 @@ int main(int argc, char *argv[]) {
const char *name(flag_I ?: base);
resign(input.data(), input.size(), output, name, entitlements, key, slots);
}
+
+ struct stat info;
+ _syscall(stat(path, &info));
+#ifndef __WIN32__
+ _syscall(chown(temp.c_str(), info.st_uid, info.st_gid));
+#endif
+ _syscall(chmod(temp.c_str(), info.st_mode));
+ _syscall(unlink(path));
+ _syscall(rename(temp.c_str(), path));
}
- Map mapping(!temp.empty() ? temp.c_str() : path, flag_T || flag_s);
+ Map mapping(path, flag_T || flag_s);
FatHeader fat_header(mapping.data(), mapping.size());
_foreach (mach_header, fat_header.GetMachHeaders()) {
@@ -1680,17 +1688,6 @@ int main(int argc, char *argv[]) {
}
}
- if (!temp.empty()) {
- struct stat info;
- _syscall(stat(path, &info));
-#ifndef __WIN32__
- _syscall(chown(temp.c_str(), info.st_uid, info.st_gid));
-#endif
- _syscall(chmod(temp.c_str(), info.st_mode));
- _syscall(unlink(path));
- _syscall(rename(temp.c_str(), path));
- }
-
++filei;
} catch (const char *) {
++filee;