From 8d6da00ff0c84d623ccdde7232e0514690d95269 Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Thu, 1 Dec 2016 13:16:13 +0000 Subject: Ijar: extract file writing logic to platform_utils This change takes us closer to compiling ijar, thus Bazel, with MSVC. Also update the StatFile method added by unknown commit to report any errors. See https://github.com/bazelbuild/bazel/issues/2157 See https://github.com/bazelbuild/bazel/issues/2107 -- MOS_MIGRATED_REVID=140719249 --- third_party/ijar/zip_main.cc | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'third_party/ijar/zip_main.cc') diff --git a/third_party/ijar/zip_main.cc b/third_party/ijar/zip_main.cc index 351faba616..4347f018ed 100644 --- a/third_party/ijar/zip_main.cc +++ b/third_party/ijar/zip_main.cc @@ -37,13 +37,6 @@ namespace devtools_ijar { -#define SYSCALL(expr) do { \ - if ((expr) < 0) { \ - perror(#expr); \ - abort(); \ - } \ - } while (0) - // // A ZipExtractorProcessor that extract files in the ZIP file. // @@ -142,20 +135,12 @@ void UnzipProcessor::Process(const char* filename, const u4 attr, } if (extract_) { char path[PATH_MAX]; - int fd; concat_path(path, PATH_MAX, output_root_, filename); // Directories created must have executable bit set and be owner writeable. // Otherwise, we cannot write or create any file inside. mkdirs(path, perm | S_IWUSR | S_IXUSR); - if (!isdir) { - fd = open(path, O_CREAT | O_WRONLY, perm); - if (fd < 0) { - fprintf(stderr, "Cannot open file %s for writing: %s\n", - path, strerror(errno)); - abort(); - } - SYSCALL(write(fd, data, size)); - SYSCALL(close(fd)); + if (!isdir && !write_file(path, perm, data, size)) { + abort(); } } } @@ -230,7 +215,6 @@ int add_file(std::unique_ptr const &builder, char *file, file_stat.file_mode = 0666; if (file != NULL) { if (!stat_file(file, &file_stat)) { - fprintf(stderr, "Cannot stat file %s: %s.\n", file, strerror(errno)); return -1; } } @@ -293,7 +277,6 @@ int add_file(std::unique_ptr const &builder, char *file, char **read_filelist(char *filename) { Stat file_stat; if (!stat_file(filename, &file_stat)) { - fprintf(stderr, "Cannot stat file %s: %s.\n", filename, strerror(errno)); return NULL; } -- cgit v1.2.3