Skip to content

Commit

Permalink
Merge pull request #64 from ctabin/libzippp-prefix-usage
Browse files Browse the repository at this point in the history
Renaming of defines to use LIBZIPPP_ prefix
  • Loading branch information
ctabin authored Apr 18, 2020
2 parents 5b1fccf + 6f6f8f6 commit 2273362
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/libzippp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ int ZipArchive::renameEntry(const ZipEntry& entry, const string& newName) const
if (newName==entry.getName()) { return LIBZIPPP_ERROR_INVALID_PARAMETER; }

if (entry.isFile()) {
if (ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name
if (LIBZIPPP_ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name

int lastSlash = newName.rfind(ENTRY_PATH_SEPARATOR);
int lastSlash = newName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR);
if (lastSlash!=1) {
bool dadded = addEntry(newName.substr(0, lastSlash+1));
if (!dadded) { return LIBZIPPP_ERROR_UNKNOWN; } //the hierarchy hasn't been created
Expand All @@ -454,9 +454,9 @@ int ZipArchive::renameEntry(const ZipEntry& entry, const string& newName) const
if (result==0) { return 1; }
return LIBZIPPP_ERROR_UNKNOWN; //renaming was not possible (entry already exists ?)
} else {
if (!ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name
if (!LIBZIPPP_ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name

int parentSlash = newName.rfind(ENTRY_PATH_SEPARATOR, newName.length()-2);
int parentSlash = newName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR, newName.length()-2);
if (parentSlash!=-1) { //updates the dir hierarchy
string parent = newName.substr(0, parentSlash+1);
bool dadded = addEntry(parent);
Expand Down Expand Up @@ -511,9 +511,9 @@ int ZipArchive::renameEntry(const string& e, const string& newName) const {
bool ZipArchive::addFile(const string& entryName, const string& file) const {
if (!isOpen()) { return false; }
if (mode==READ_ONLY) { return false; } //adding not allowed
if (ENTRY_IS_DIRECTORY(entryName)) { return false; }
if (LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; }

int lastSlash = entryName.rfind(ENTRY_PATH_SEPARATOR);
int lastSlash = entryName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR);
if (lastSlash!=-1) { //creates the needed parent directories
string dirEntry = entryName.substr(0, lastSlash+1);
bool dadded = addEntry(dirEntry);
Expand Down Expand Up @@ -541,9 +541,9 @@ bool ZipArchive::addFile(const string& entryName, const string& file) const {
bool ZipArchive::addData(const string& entryName, const void* data, libzippp_uint64 length, bool freeData) const {
if (!isOpen()) { return false; }
if (mode==READ_ONLY) { return false; } //adding not allowed
if (ENTRY_IS_DIRECTORY(entryName)) { return false; }
if (LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; }

int lastSlash = entryName.rfind(ENTRY_PATH_SEPARATOR);
int lastSlash = entryName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR);
if (lastSlash!=-1) { //creates the needed parent directories
string dirEntry = entryName.substr(0, lastSlash+1);
bool dadded = addEntry(dirEntry);
Expand All @@ -564,16 +564,16 @@ bool ZipArchive::addData(const string& entryName, const void* data, libzippp_uin
bool ZipArchive::addEntry(const string& entryName) const {
if (!isOpen()) { return false; }
if (mode==READ_ONLY) { return false; } //adding not allowed
if (!ENTRY_IS_DIRECTORY(entryName)) { return false; }
if (!LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; }

int nextSlash = entryName.find(ENTRY_PATH_SEPARATOR);
int nextSlash = entryName.find(LIBZIPPP_ENTRY_PATH_SEPARATOR);
while (nextSlash!=-1) {
string pathToCreate = entryName.substr(0, nextSlash+1);
if (!hasEntry(pathToCreate)) {
libzippp_int64 result = zip_dir_add(zipHandle, pathToCreate.c_str(), ZIP_FL_ENC_GUESS);
if (result==-1) { return false; }
}
nextSlash = entryName.find(ENTRY_PATH_SEPARATOR, nextSlash+1);
nextSlash = entryName.find(LIBZIPPP_ENTRY_PATH_SEPARATOR, nextSlash+1);
}

return true;
Expand All @@ -589,7 +589,7 @@ int ZipArchive::readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, Stat
struct zip_file* zipFile = zip_fopen_index(zipHandle, zipEntry.getIndex(), flag);
if (zipFile) {
libzippp_uint64 maxSize = zipEntry.getSize();
if (!chunksize) { chunksize = DEFAULT_CHUNK_SIZE; } // use the default chunk size (512K) if not specified by the user
if (!chunksize) { chunksize = LIBZIPPP_DEFAULT_CHUNK_SIZE; } // use the default chunk size (512K) if not specified by the user

if (maxSize<chunksize) {
char* data = NEW_CHAR_ARRAY(maxSize)
Expand Down
16 changes: 8 additions & 8 deletions src/libzippp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
struct zip;
struct zip_source;

#define ENTRY_PATH_SEPARATOR '/'
#define ENTRY_IS_DIRECTORY(str) ((str).length()>0 && (str)[(str).length()-1]==ENTRY_PATH_SEPARATOR)
#define DEFAULT_CHUNK_SIZE 524288
#define LIBZIPPP_ENTRY_PATH_SEPARATOR '/'
#define LIBZIPPP_ENTRY_IS_DIRECTORY(str) ((str).length()>0 && (str)[(str).length()-1]==LIBZIPPP_ENTRY_PATH_SEPARATOR)
#define LIBZIPPP_DEFAULT_CHUNK_SIZE 524288

//libzip documentation
//- http://www.nih.at/libzip/libzip.html
Expand Down Expand Up @@ -303,10 +303,10 @@ namespace libzippp {
* a memory allocation has failed, LIBZIPPP_ERROR_FREAD_FAILURE if zip_fread() didn't succeed to read data,
* LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE if the last ofstream operation has failed, LIBZIPPP_ERROR_OWRITE_FAILURE if fread() didn't
* return the exact amount of requested bytes and -9 if the amount of extracted bytes didn't match the size of the file (unknown error).
* If the provided chunk size is zero, it will be defaulted to DEFAULT_CHUNK_SIZE (512KB).
* If the provided chunk size is zero, it will be defaulted to LIBZIPPP_DEFAULT_CHUNK_SIZE (512KB).
* The method doesn't close the ofstream after the extraction.
*/
int readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, State state=CURRENT, libzippp_uint64 chunksize=DEFAULT_CHUNK_SIZE) const;
int readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, State state=CURRENT, libzippp_uint64 chunksize=LIBZIPPP_DEFAULT_CHUNK_SIZE) const;

/**
* Deletes the specified entry from the zip file. If the entry is a folder, all its
Expand Down Expand Up @@ -462,7 +462,7 @@ namespace libzippp {
/**
* Returns true if the entry is a directory.
*/
inline bool isDirectory(void) const { return ENTRY_IS_DIRECTORY(name); }
inline bool isDirectory(void) const { return LIBZIPPP_ENTRY_IS_DIRECTORY(name); }

/**
* Returns true if the entry is a file.
Expand Down Expand Up @@ -517,10 +517,10 @@ namespace libzippp {
* a memory allocation has failed, LIBZIPPP_ERROR_FREAD_FAILURE if zip_fread() didn't succeed to read data,
* LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE if the last ofstream operation has failed, LIBZIPPP_ERROR_OWRITE_FAILURE if fread() didn't
* return the exact amount of requested bytes and -9 if the amount of extracted bytes didn't match the size of the file (unknown error).
* If the provided chunk size is zero, it will be defaulted to DEFAULT_CHUNK_SIZE (512KB).
* If the provided chunk size is zero, it will be defaulted to LIBZIPPP_DEFAULT_CHUNK_SIZE (512KB).
* The method doesn't close the ofstream after the extraction.
*/
int readContent(std::ostream& ofOutput, ZipArchive::State state=ZipArchive::CURRENT, libzippp_uint64 chunksize=DEFAULT_CHUNK_SIZE) const;
int readContent(std::ostream& ofOutput, ZipArchive::State state=ZipArchive::CURRENT, libzippp_uint64 chunksize=LIBZIPPP_DEFAULT_CHUNK_SIZE) const;

private:
const ZipArchive* zipFile;
Expand Down

0 comments on commit 2273362

Please sign in to comment.