diff options
author | 2018-07-18 00:53:34 -0700 | |
---|---|---|
committer | 2018-07-18 00:55:06 -0700 | |
commit | 38fa8507198fd0ed8579d0ced1b1349a7dc54c53 (patch) | |
tree | 1f5970ef9b4e3d5c1429b989f807249161abe3ba /src/tools | |
parent | a22ad80b416e5f603fe9e82ba05f72cf42573f86 (diff) |
[singlejar] Change off_t and ssize_t to C standard ptrdiff_t
MSVC does not have `ssize_t` type. MSVC does have `off_t`, but is defined as 32-bit `long` due to legacy reason, this will prevent us from handling large file.
Changing `off_t` and `ssize_t` to C standard `ptrdiff_t` for portability and consistency.
Changing one instance of `S_ISDIR(st.st_mode)` to `(st.st_mode & S_IFDIR) == S_IFDIR` as MSVC does not have `S_ISDIR` macro.
/cc @laszlocsomor
Closes #5538.
PiperOrigin-RevId: 205038203
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/singlejar/output_jar.cc | 18 | ||||
-rw-r--r-- | src/tools/singlejar/output_jar.h | 15 |
2 files changed, 20 insertions, 13 deletions
diff --git a/src/tools/singlejar/output_jar.cc b/src/tools/singlejar/output_jar.cc index 6728d59de8..75be4ca1c7 100644 --- a/src/tools/singlejar/output_jar.cc +++ b/src/tools/singlejar/output_jar.cc @@ -416,7 +416,7 @@ bool OutputJar::AddJar(int jar_path_index) { // local header // file data // data descriptor, if present. - off_t copy_from = jar_entry->local_header_offset(); + off64_t copy_from = jar_entry->local_header_offset(); size_t num_bytes = lh->size(); if (jar_entry->no_size_in_local_header()) { const DDR *ddr = reinterpret_cast<const DDR *>( @@ -429,7 +429,7 @@ bool OutputJar::AddJar(int jar_path_index) { } else { num_bytes += lh->compressed_file_size(); } - off_t local_header_offset = Position(); + off64_t local_header_offset = Position(); // When normalize_timestamps is set, entry's timestamp is to be set to // 01/01/1980 00:00:00 (or to 01/01/1980 00:00:02, if an entry is a .class @@ -499,7 +499,7 @@ bool OutputJar::AddJar(int jar_path_index) { return input_jar.Close(); } -off_t OutputJar::Position() { +off64_t OutputJar::Position() { if (file_ == nullptr) { diag_err(1, "%s:%d: output file is not open", __FILE__, __LINE__); } @@ -551,7 +551,7 @@ void OutputJar::WriteEntry(void *buffer) { } uint8_t *data = reinterpret_cast<uint8_t *>(entry); - off_t output_position = Position(); + off64_t output_position = Position(); if (!WriteBytes(data, entry->data() + entry->in_zip_size() - data)) { diag_err(1, "%s:%d: write", __FILE__, __LINE__); } @@ -636,7 +636,7 @@ void OutputJar::WriteDirEntry(const std::string &name, } // Create output Central Directory entry for the input jar entry. -void OutputJar::AppendToDirectoryBuffer(const CDH *cdh, off_t lh_pos, +void OutputJar::AppendToDirectoryBuffer(const CDH *cdh, off64_t lh_pos, uint16_t normalized_time, bool fix_timestamp) { // While copying from the input CDH pointed to by 'cdh', we may need to drop @@ -777,7 +777,7 @@ bool OutputJar::Close() { WriteEntry(spring_schemas_.OutputEntry(options_->force_compression)); WriteEntry(protobuf_meta_handler_.OutputEntry(options_->force_compression)); // TODO(asmundak): handle manifest; - off_t output_position = Position(); + off64_t output_position = Position(); bool write_zip64_ecd = output_position >= 0xFFFFFFFF || entries_ >= 0xFFFF || cen_size_ >= 0xFFFFFFFF; @@ -814,7 +814,7 @@ bool OutputJar::Close() { // affects javac and javah only, 'jar' experiences no problems. ecd->cen_size32(std::min(cen_size, static_cast<size_t>(0xFFFFFFFFUL))); ecd->cen_offset32( - std::min(output_position, static_cast<off_t>(0x0FFFFFFFFL))); + std::min(output_position, static_cast<off64_t>(0x0FFFFFFFFL))); } } else { ECD *ecd = reinterpret_cast<ECD *>(ReserveCdh(sizeof(ECD))); @@ -855,7 +855,7 @@ bool IsDir(const std::string &path) { diag_warn("%s:%d: stat %s:", __FILE__, __LINE__, path.c_str()); return false; } - return S_ISDIR(st.st_mode); + return (st.st_mode & S_IFDIR) == S_IFDIR; } void OutputJar::ClasspathResource(const std::string &resource_name, @@ -890,7 +890,7 @@ void OutputJar::ClasspathResource(const std::string &resource_name, } } -ssize_t OutputJar::AppendFile(int in_fd, off_t offset, size_t count) { +ssize_t OutputJar::AppendFile(int in_fd, off64_t offset, size_t count) { if (count == 0) { return 0; } diff --git a/src/tools/singlejar/output_jar.h b/src/tools/singlejar/output_jar.h index ae26187792..3f66d4081e 100644 --- a/src/tools/singlejar/output_jar.h +++ b/src/tools/singlejar/output_jar.h @@ -18,6 +18,7 @@ #include <stdio.h> #include <cinttypes> +#include <cstddef> #include <memory> #include <string> #include <unordered_map> @@ -26,6 +27,12 @@ #include "src/tools/singlejar/combiners.h" #include "src/tools/singlejar/options.h" +#if defined(__APPLE__) +typedef off_t off64_t; +#elif defined(_WIN32) +typedef __int64 off64_t; +#endif + /* * Jar file we are writing. */ @@ -70,7 +77,7 @@ class OutputJar { // Add the contents of the given input jar. bool AddJar(int jar_path_index); // Returns the current output position. - off_t Position(); + off64_t Position(); // Write Jar entry. void WriteEntry(void *local_header_and_payload); // Write META_INF/ entry (the first entry on output). @@ -80,7 +87,7 @@ class OutputJar { const uint16_t n_extra_fields); // Create output Central Directory Header for the given input entry and // append it to CEN (Central Directory) buffer. - void AppendToDirectoryBuffer(const CDH *cdh, off_t local_header_offset, + void AppendToDirectoryBuffer(const CDH *cdh, off64_t lh_pos, uint16_t normalized_time, bool fix_timestamp); // Reserve space in CEN buffer. uint8_t *ReserveCdr(size_t chunk_size); @@ -92,7 +99,7 @@ class OutputJar { void ClasspathResource(const std::string& resource_name, const std::string& resource_path); // Copy 'count' bytes starting at 'offset' from the given file. - ssize_t AppendFile(int in_fd, off_t offset, size_t count); + ssize_t AppendFile(int in_fd, off64_t offset, size_t count); // Write bytes to the output file, return true on success. bool WriteBytes(const void *buffer, size_t count); @@ -107,7 +114,7 @@ class OutputJar { std::unordered_map<std::string, struct EntryInfo> known_members_; FILE *file_; - off_t outpos_; + off64_t outpos_; std::unique_ptr<char[]> buffer_; int entries_; int duplicate_entries_; |