From 34f4c1d83e1746db11f245349b3131180348d04c Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 27 Sep 2015 03:35:27 -0700 Subject: Simplify implementation of temporary reallocation. --- ldid.cpp | 25 +++++++++++-------------- 1 file 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; -- cgit v1.2.3-56-ge451