util/disk_cache: mark read-only arguments const

No functional changes.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Grazvydas Ignotas
2017-03-05 22:58:52 +02:00
committed by Timothy Arceri
parent b19caecbd6
commit 175d4aa8f5
2 changed files with 28 additions and 27 deletions

View File

@@ -80,7 +80,7 @@ struct disk_cache {
* -1 in all other cases. * -1 in all other cases.
*/ */
static int static int
mkdir_if_needed(char *path) mkdir_if_needed(const char *path)
{ {
struct stat sb; struct stat sb;
@@ -118,7 +118,7 @@ mkdir_if_needed(char *path)
* <path>/<name> cannot be created as a directory * <path>/<name> cannot be created as a directory
*/ */
static char * 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; char *new_path;
struct stat sb; struct stat sb;
@@ -147,7 +147,8 @@ remove_dir(const char *fpath, const struct stat *sb,
} }
static void 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); DIR *dir = opendir(path);
@@ -170,7 +171,7 @@ remove_old_cache_directories(void *mem_ctx, char *path, const char *timestamp)
} }
static char * 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) const char *gpu_name)
{ {
char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa"); 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. * Returns NULL if out of memory.
*/ */
static char * 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 buf[41];
char *filename; char *filename;
@@ -422,7 +423,7 @@ get_cache_file(struct disk_cache *cache, cache_key key)
* _get_cache_file above. * _get_cache_file above.
*/ */
static void 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 *dir;
char buf[41]; char buf[41];
@@ -445,7 +446,7 @@ make_cache_file_directory(struct disk_cache *cache, cache_key key)
*/ */
static char * static char *
choose_random_file_matching(const char *dir_path, choose_random_file_matching(const char *dir_path,
bool (*predicate)(struct dirent *, bool (*predicate)(const struct dirent *,
const char *dir_path)) const char *dir_path))
{ {
DIR *dir; DIR *dir;
@@ -508,7 +509,7 @@ choose_random_file_matching(const char *dir_path,
* ".tmp" * ".tmp"
*/ */
static bool 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; char *filename;
if (asprintf(&filename, "%s/%s", path, entry->d_name) == -1) 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 "..") * special name of "..")
*/ */
static bool 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; char *subdir;
if (asprintf(&subdir, "%s/%s", path, entry->d_name) == -1) if (asprintf(&subdir, "%s/%s", path, entry->d_name) == -1)
@@ -625,7 +626,7 @@ evict_random_item(struct disk_cache *cache)
} }
void 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; struct stat sb;
@@ -658,7 +659,7 @@ disk_cache_remove(struct disk_cache *cache, cache_key key)
*/ */
static size_t static size_t
deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest, 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]; unsigned char out[BUFSIZE];
@@ -725,7 +726,7 @@ struct cache_entry_file_data {
void void
disk_cache_put(struct disk_cache *cache, disk_cache_put(struct disk_cache *cache,
cache_key key, const cache_key key,
const void *data, const void *data,
size_t size) size_t size)
{ {
@@ -871,7 +872,7 @@ inflate_cache_data(uint8_t *in_data, size_t in_data_size,
} }
void * 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; int fd = -1, ret, len;
struct stat sb; struct stat sb;
@@ -949,9 +950,9 @@ disk_cache_get(struct disk_cache *cache, cache_key key, size_t *size)
} }
void 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; int i = *key_chunk & CACHE_INDEX_KEY_MASK;
unsigned char *entry; unsigned char *entry;
@@ -968,9 +969,9 @@ disk_cache_put_key(struct disk_cache *cache, cache_key key)
* extra recompile. * extra recompile.
*/ */
bool 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; int i = *key_chunk & CACHE_INDEX_KEY_MASK;
unsigned char *entry; unsigned char *entry;

View File

@@ -104,7 +104,7 @@ disk_cache_destroy(struct disk_cache *cache);
* Remove the item in the cache under the name \key. * Remove the item in the cache under the name \key.
*/ */
void 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. * 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. * evicted from the cache.
*/ */
void 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); 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. * caller should call free() it when finished.
*/ */
void * 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). * 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. * evicted from the cache.
*/ */
void 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. * 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. * disk_cache_has_key() to return true for the same key.
*/ */
bool 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 #else
@@ -174,32 +174,32 @@ disk_cache_destroy(struct disk_cache *cache) {
} }
static inline void 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) const void *data, size_t size)
{ {
return; return;
} }
static inline void 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; return;
} }
static inline uint8_t * 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; return NULL;
} }
static inline void 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; return;
} }
static inline bool 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; return false;
} }