diff --git a/libziparchive/include/ziparchive/zip_writer.h b/libziparchive/include/ziparchive/zip_writer.h index bd44fdb4d..a2a0dbfd2 100644 --- a/libziparchive/include/ziparchive/zip_writer.h +++ b/libziparchive/include/ziparchive/zip_writer.h @@ -21,6 +21,7 @@ #include #include +#include #include #include "android-base/macros.h" @@ -101,7 +102,7 @@ class ZipWriter { * Subsequent calls to WriteBytes(const void*, size_t) will add data to this entry. * Returns 0 on success, and an error value < 0 on failure. */ - int32_t StartEntry(const char* path, size_t flags); + int32_t StartEntry(std::string_view path, size_t flags); /** * Starts a new zip entry with the given path and flags, where the @@ -111,17 +112,17 @@ class ZipWriter { * Subsequent calls to WriteBytes(const void*, size_t) will add data to this entry. * Returns 0 on success, and an error value < 0 on failure. */ - int32_t StartAlignedEntry(const char* path, size_t flags, uint32_t alignment); + int32_t StartAlignedEntry(std::string_view path, size_t flags, uint32_t alignment); /** * Same as StartEntry(const char*, size_t), but sets a last modified time for the entry. */ - int32_t StartEntryWithTime(const char* path, size_t flags, time_t time); + int32_t StartEntryWithTime(std::string_view path, size_t flags, time_t time); /** * Same as StartAlignedEntry(const char*, size_t), but sets a last modified time for the entry. */ - int32_t StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, uint32_t alignment); + int32_t StartAlignedEntryWithTime(std::string_view path, size_t flags, time_t time, uint32_t alignment); /** * Writes bytes to the zip file for the previously started zip entry. diff --git a/libziparchive/zip_writer.cc b/libziparchive/zip_writer.cc index ae9d14514..3c5320941 100644 --- a/libziparchive/zip_writer.cc +++ b/libziparchive/zip_writer.cc @@ -130,7 +130,7 @@ int32_t ZipWriter::HandleError(int32_t error_code) { return error_code; } -int32_t ZipWriter::StartEntry(const char* path, size_t flags) { +int32_t ZipWriter::StartEntry(std::string_view path, size_t flags) { uint32_t alignment = 0; if (flags & kAlign32) { flags &= ~kAlign32; @@ -139,11 +139,11 @@ int32_t ZipWriter::StartEntry(const char* path, size_t flags) { return StartAlignedEntryWithTime(path, flags, time_t(), alignment); } -int32_t ZipWriter::StartAlignedEntry(const char* path, size_t flags, uint32_t alignment) { +int32_t ZipWriter::StartAlignedEntry(std::string_view path, size_t flags, uint32_t alignment) { return StartAlignedEntryWithTime(path, flags, time_t(), alignment); } -int32_t ZipWriter::StartEntryWithTime(const char* path, size_t flags, time_t time) { +int32_t ZipWriter::StartEntryWithTime(std::string_view path, size_t flags, time_t time) { uint32_t alignment = 0; if (flags & kAlign32) { flags &= ~kAlign32; @@ -198,7 +198,7 @@ static void CopyFromFileEntry(const ZipWriter::FileEntry& src, bool use_data_des dst->extra_field_length = src.padding_length; } -int32_t ZipWriter::StartAlignedEntryWithTime(const char* path, size_t flags, time_t time, +int32_t ZipWriter::StartAlignedEntryWithTime(std::string_view path, size_t flags, time_t time, uint32_t alignment) { if (state_ != State::kWritingZip) { return kInvalidState; @@ -265,7 +265,7 @@ int32_t ZipWriter::StartAlignedEntryWithTime(const char* path, size_t flags, tim return HandleError(kIoError); } - if (fwrite(path, sizeof(*path), file_entry.path.size(), file_) != file_entry.path.size()) { + if (fwrite(path.data(), 1, path.size(), file_) != path.size()) { return HandleError(kIoError); }