mz_os.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* mz_os.h -- System functions
  2. Version 2.9.2, February 12, 2020
  3. part of the MiniZip project
  4. Copyright (C) 2010-2020 Nathan Moinvaziri
  5. https://github.com/nmoinvaz/minizip
  6. This program is distributed under the terms of the same license as zlib.
  7. See the accompanying LICENSE file for the full text of the license.
  8. */
  9. #ifndef MZ_OS_H
  10. #define MZ_OS_H
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /***************************************************************************/
  15. #if defined(__APPLE__)
  16. # define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
  17. #elif defined(__riscos__)
  18. # define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_RISCOS)
  19. #elif defined(__unix__)
  20. # define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
  21. #elif defined(_WIN32)
  22. # define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
  23. #endif
  24. #if defined(HAVE_LZMA)
  25. # define MZ_VERSION_MADEBY_ZIP_VERSION (63)
  26. #elif defined(HAVE_WZAES)
  27. # define MZ_VERSION_MADEBY_ZIP_VERSION (51)
  28. #elif defined(HAVE_BZIP2)
  29. # define MZ_VERSION_MADEBY_ZIP_VERSION (46)
  30. #else
  31. # define MZ_VERSION_MADEBY_ZIP_VERSION (45)
  32. #endif
  33. #define MZ_VERSION_MADEBY ((MZ_VERSION_MADEBY_HOST_SYSTEM << 8) | \
  34. (MZ_VERSION_MADEBY_ZIP_VERSION))
  35. #define MZ_PATH_SLASH_UNIX ('/')
  36. #if defined(_WIN32)
  37. # define MZ_PATH_SLASH_PLATFORM ('\\')
  38. #else
  39. # define MZ_PATH_SLASH_PLATFORM (MZ_PATH_SLASH_UNIX)
  40. #endif
  41. /***************************************************************************/
  42. #if defined(_WIN32)
  43. struct dirent {
  44. char d_name[256];
  45. };
  46. typedef void* DIR;
  47. #else
  48. #include <dirent.h>
  49. #endif
  50. /***************************************************************************/
  51. /* Shared functions */
  52. int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
  53. /* Combines two paths */
  54. int32_t mz_path_append_slash(char *path, int32_t max_path, char slash);
  55. /* Appends a path slash on to the end of the path */
  56. int32_t mz_path_remove_slash(char *path);
  57. /* Removes a path slash from the end of the path */
  58. int32_t mz_path_has_slash(const char *path);
  59. /* Returns whether or not the path ends with slash */
  60. int32_t mz_path_convert_slashes(char *path, char slash);
  61. /* Converts the slashes in a path */
  62. int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
  63. /* Compare two paths with wildcard */
  64. int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
  65. /* Resolves path */
  66. int32_t mz_path_remove_filename(char *path);
  67. /* Remove the filename from a path */
  68. int32_t mz_path_remove_extension(char *path);
  69. /* Remove the extension from a path */
  70. int32_t mz_path_get_filename(const char *path, const char **filename);
  71. /* Get the filename from a path */
  72. int32_t mz_dir_make(const char *path);
  73. /* Creates a directory recursively */
  74. int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
  75. /* Gets the crc32 hash of a file */
  76. /***************************************************************************/
  77. /* Platform specific functions */
  78. wchar_t *mz_os_unicode_string_create(const char *string, int32_t encoding);
  79. /* Create unicode string from a utf8 string */
  80. void mz_os_unicode_string_delete(wchar_t **string);
  81. /* Delete a unicode string that was created */
  82. uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding);
  83. /* Create a utf8 string from a string with another encoding */
  84. void mz_os_utf8_string_delete(uint8_t **string);
  85. /* Delete a utf8 string that was created */
  86. int32_t mz_os_rand(uint8_t *buf, int32_t size);
  87. /* Random number generator (not cryptographically secure) */
  88. int32_t mz_os_rename(const char *source_path, const char *target_path);
  89. /* Rename a file */
  90. int32_t mz_os_unlink(const char *path);
  91. /* Delete an existing file */
  92. int32_t mz_os_file_exists(const char *path);
  93. /* Check to see if a file exists */
  94. int64_t mz_os_get_file_size(const char *path);
  95. /* Gets the length of a file */
  96. int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
  97. /* Gets a file's modified, access, and creation dates if supported */
  98. int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
  99. /* Sets a file's modified, access, and creation dates if supported */
  100. int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes);
  101. /* Gets a file's attributes */
  102. int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes);
  103. /* Sets a file's attributes */
  104. int32_t mz_os_make_dir(const char *path);
  105. /* Recursively creates a directory */
  106. DIR* mz_os_open_dir(const char *path);
  107. /* Opens a directory for listing */
  108. struct
  109. dirent* mz_os_read_dir(DIR *dir);
  110. /* Reads a directory listing entry */
  111. int32_t mz_os_close_dir(DIR *dir);
  112. /* Closes a directory that has been opened for listing */
  113. int32_t mz_os_is_dir(const char *path);
  114. /* Checks to see if path is a directory */
  115. int32_t mz_os_is_symlink(const char *path);
  116. /* Checks to see if path is a symbolic link */
  117. int32_t mz_os_make_symlink(const char *path, const char *target_path);
  118. /* Creates a symbolic link pointing to a target */
  119. int32_t mz_os_read_symlink(const char *path, char *target_path, int32_t max_target_path);
  120. /* Gets the target path for a symbolic link */
  121. uint64_t mz_os_ms_time(void);
  122. /* Gets the time in milliseconds */
  123. /***************************************************************************/
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif