mz_os.h 5.4 KB

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