Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose zlib constants for backwards compat #815

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions compat/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
Encryption is not supported.
*/

#ifndef _ZLIB_H
# if (ZLIB_VERNUM < 0x1270)
typedef unsigned long z_crc_t;
# else
typedef uint32_t z_crc_t;
# endif
#ifndef ZLIB_VERNUM
/* No zlib */
typedef uint32_t z_crc_t;
#elif (ZLIB_VERNUM & 0xf != 0xf) && (ZLIB_VERNUM < 0x1270)
/* Define z_crc_t in zlib 1.2.6 and less */
typedef unsigned long z_crc_t;
#elif (ZLIB_VERNUM & 0xf == 0xf) && (ZLIB_VERNUM < 0x12df)
/* Define z_crc_t in zlib-ng 2.0.7 and less */
typedef unsigned int z_crc_t;
#endif

#define CRC32(c, b) ((*(pcrc_32_tab + (((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
Expand Down
8 changes: 6 additions & 2 deletions compat/ioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

#include <stdint.h>

#ifndef _ZLIB_H
//#include "zlib.h"
#if !defined(_ZLIB_H) && !defined(ZLIB_H) && !defined(ZLIB_H_)
# if __has_include(<zlib-ng.h>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid __has_include is not available in MSVC?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it will only work if included into C++ file?

Copy link
Contributor Author

@Coeur Coeur Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__has_include is in VS 2017 15.3: https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170

Do we care about obsolete versions of Visual Studio which are more than 7 years old?

[edit]
Ah, maybe you meant that VS support is only for C++, as stated here:
https://stackoverflow.com/questions/71540280/make-has-include-portable-in-c

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Contributor Author

@Coeur Coeur Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmoinvaz can we merge this PR as it is, and deal with VS separately?
Otherwise, I guess, all what is needed is to add some nearly empty ioapi.cc file which just contains include "ioapi.h"? But I'm worried it could affect other platforms which don't expect C++ code.

# include <zlib-ng.h>
# elif __has_include(<zlib.h>)
# include <zlib.h>
# endif
#endif

typedef uint64_t ZPOS64_T;
Expand Down
12 changes: 0 additions & 12 deletions compat/unzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ typedef void *unzFile;

/***************************************************************************/

#ifndef Z_ERRNO
#define Z_ERRNO (-1)
#endif
#ifndef Z_DEFLATED
#define Z_DEFLATED (8)
#endif
#ifndef Z_BZIP2ED
#define Z_BZIP2ED (12)
#endif

/***************************************************************************/

#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
Expand Down
10 changes: 0 additions & 10 deletions compat/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ typedef void *zipFile;

/***************************************************************************/

#ifndef Z_ERRNO
#define Z_ERRNO (-1)
#endif
#ifndef Z_DEFLATED
#define Z_DEFLATED (8)
#endif
#ifndef Z_BZIP2ED
#define Z_BZIP2ED (12)
#endif

#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
Expand Down
12 changes: 8 additions & 4 deletions mz_crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {

uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size) {
#if defined(HAVE_ZLIB)
/* Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng */
# if (ZLIB_VERNUM < 0x1270)
typedef unsigned long z_crc_t;
# else
# ifndef ZLIB_VERNUM
/* HAVE_ZLIB but no ZLIB_VERNUM? */
typedef uint32_t z_crc_t;
# elif (ZLIB_VERNUM & 0xf != 0xf) && (ZLIB_VERNUM < 0x1270)
/* Define z_crc_t in zlib 1.2.6 and less */
typedef unsigned long z_crc_t;
# elif (ZLIB_VERNUM & 0xf == 0xf) && (ZLIB_VERNUM < 0x12df)
/* Define z_crc_t in zlib-ng 2.0.7 and less */
typedef unsigned int z_crc_t;
# endif
return (uint32_t)ZLIB_PREFIX(crc32)((z_crc_t)value, buf, (uInt)size);
#elif defined(HAVE_LZMA)
Expand Down
Loading