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