From 175d4aa8f52a01dd21fb3774c9638a866da5dca8 Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Sun, 5 Mar 2017 22:58:52 +0200 Subject: [PATCH] util/disk_cache: mark read-only arguments const No functional changes. Signed-off-by: Grazvydas Ignotas Reviewed-by: Timothy Arceri --- src/util/disk_cache.c | 35 ++++++++++++++++++----------------- src/util/disk_cache.h | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index fafd32992f8..198d90e4222 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -80,7 +80,7 @@ struct disk_cache { * -1 in all other cases. */ static int -mkdir_if_needed(char *path) +mkdir_if_needed(const char *path) { struct stat sb; @@ -118,7 +118,7 @@ mkdir_if_needed(char *path) * / cannot be created as a directory */ static char * -concatenate_and_mkdir(void *ctx, char *path, const char *name) +concatenate_and_mkdir(void *ctx, const char *path, const char *name) { char *new_path; struct stat sb; @@ -147,7 +147,8 @@ remove_dir(const char *fpath, const struct stat *sb, } static void -remove_old_cache_directories(void *mem_ctx, char *path, const char *timestamp) +remove_old_cache_directories(void *mem_ctx, const char *path, + const char *timestamp) { DIR *dir = opendir(path); @@ -170,7 +171,7 @@ remove_old_cache_directories(void *mem_ctx, char *path, const char *timestamp) } static char * -create_mesa_cache_dir(void *mem_ctx, char *path, const char *timestamp, +create_mesa_cache_dir(void *mem_ctx, const char *path, const char *timestamp, const char *gpu_name) { char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa"); @@ -403,7 +404,7 @@ disk_cache_destroy(struct disk_cache *cache) * Returns NULL if out of memory. */ static char * -get_cache_file(struct disk_cache *cache, cache_key key) +get_cache_file(struct disk_cache *cache, const cache_key key) { char buf[41]; char *filename; @@ -422,7 +423,7 @@ get_cache_file(struct disk_cache *cache, cache_key key) * _get_cache_file above. */ static void -make_cache_file_directory(struct disk_cache *cache, cache_key key) +make_cache_file_directory(struct disk_cache *cache, const cache_key key) { char *dir; char buf[41]; @@ -445,7 +446,7 @@ make_cache_file_directory(struct disk_cache *cache, cache_key key) */ static char * choose_random_file_matching(const char *dir_path, - bool (*predicate)(struct dirent *, + bool (*predicate)(const struct dirent *, const char *dir_path)) { DIR *dir; @@ -508,7 +509,7 @@ choose_random_file_matching(const char *dir_path, * ".tmp" */ static bool -is_regular_non_tmp_file(struct dirent *entry, const char *path) +is_regular_non_tmp_file(const struct dirent *entry, const char *path) { char *filename; if (asprintf(&filename, "%s/%s", path, entry->d_name) == -1) @@ -555,7 +556,7 @@ unlink_random_file_from_directory(const char *path) * special name of "..") */ static bool -is_two_character_sub_directory(struct dirent *entry, const char *path) +is_two_character_sub_directory(const struct dirent *entry, const char *path) { char *subdir; if (asprintf(&subdir, "%s/%s", path, entry->d_name) == -1) @@ -625,7 +626,7 @@ evict_random_item(struct disk_cache *cache) } void -disk_cache_remove(struct disk_cache *cache, cache_key key) +disk_cache_remove(struct disk_cache *cache, const cache_key key) { struct stat sb; @@ -658,7 +659,7 @@ disk_cache_remove(struct disk_cache *cache, cache_key key) */ static size_t deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest, - char *filename) + const char *filename) { unsigned char out[BUFSIZE]; @@ -725,7 +726,7 @@ struct cache_entry_file_data { void disk_cache_put(struct disk_cache *cache, - cache_key key, + const cache_key key, const void *data, size_t size) { @@ -871,7 +872,7 @@ inflate_cache_data(uint8_t *in_data, size_t in_data_size, } void * -disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size) +disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size) { int fd = -1, ret, len; struct stat sb; @@ -949,9 +950,9 @@ disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size) } void -disk_cache_put_key(struct disk_cache *cache, cache_key key) +disk_cache_put_key(struct disk_cache *cache, const cache_key key) { - uint32_t *key_chunk = (uint32_t *) key; + const uint32_t *key_chunk = (const uint32_t *) key; int i = *key_chunk & CACHE_INDEX_KEY_MASK; unsigned char *entry; @@ -968,9 +969,9 @@ disk_cache_put_key(struct disk_cache *cache, cache_key key) * extra recompile. */ bool -disk_cache_has_key(struct disk_cache *cache, cache_key key) +disk_cache_has_key(struct disk_cache *cache, const cache_key key) { - uint32_t *key_chunk = (uint32_t *) key; + const uint32_t *key_chunk = (const uint32_t *) key; int i = *key_chunk & CACHE_INDEX_KEY_MASK; unsigned char *entry; diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index b7c0df25dd1..63ab9b35e2c 100644 --- a/src/util/disk_cache.h +++ b/src/util/disk_cache.h @@ -104,7 +104,7 @@ disk_cache_destroy(struct disk_cache *cache); * Remove the item in the cache under the name \key. */ void -disk_cache_remove(struct disk_cache *cache, cache_key key); +disk_cache_remove(struct disk_cache *cache, const cache_key key); /** * Store an item in the cache under the name \key. @@ -116,7 +116,7 @@ disk_cache_remove(struct disk_cache *cache, cache_key key); * evicted from the cache. */ void -disk_cache_put(struct disk_cache *cache, cache_key key, +disk_cache_put(struct disk_cache *cache, const cache_key key, const void *data, size_t size); /** @@ -133,7 +133,7 @@ disk_cache_put(struct disk_cache *cache, cache_key key, * caller should call free() it when finished. */ void * -disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size); +disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size); /** * Store the name \key within the cache, (without any associated data). @@ -145,7 +145,7 @@ disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size); * evicted from the cache. */ void -disk_cache_put_key(struct disk_cache *cache, cache_key key); +disk_cache_put_key(struct disk_cache *cache, const cache_key key); /** * Test whether the name \key was previously recorded in the cache. @@ -158,7 +158,7 @@ disk_cache_put_key(struct disk_cache *cache, cache_key key); * disk_cache_has_key() to return true for the same key. */ bool -disk_cache_has_key(struct disk_cache *cache, cache_key key); +disk_cache_has_key(struct disk_cache *cache, const cache_key key); #else @@ -174,32 +174,32 @@ disk_cache_destroy(struct disk_cache *cache) { } static inline void -disk_cache_put(struct disk_cache *cache, cache_key key, +disk_cache_put(struct disk_cache *cache, const cache_key key, const void *data, size_t size) { return; } static inline void -disk_cache_remove(struct disk_cache *cache, cache_key key) +disk_cache_remove(struct disk_cache *cache, const cache_key key) { return; } static inline uint8_t * -disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size) +disk_cache_get(struct disk_cache *cache, const cache_key key, size_t *size) { return NULL; } static inline void -disk_cache_put_key(struct disk_cache *cache, cache_key key) +disk_cache_put_key(struct disk_cache *cache, const cache_key key) { return; } static inline bool -disk_cache_has_key(struct disk_cache *cache, cache_key key) +disk_cache_has_key(struct disk_cache *cache, const cache_key key) { return false; } -- 2.30.2