Skip to content

Commit 54bc1b6

Browse files
committed
Cleaned up the Mach-O archive cache
1 parent 673be14 commit 54bc1b6

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/parser/file/macho/cache.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
* CallstackLibrary, see the file LICENSE. If not, see <https://www.gnu.org/licenses/>.
2020
*/
2121

22+
#include "cache.h"
23+
2224
#include <stdbool.h>
2325
#include <string.h>
2426

2527
#include "archive.h"
26-
#include "cache.h"
27-
2828
#include "../vector_string.h"
2929

3030
/**
@@ -42,27 +42,28 @@ static struct macho_cache {
4242
/**
4343
* @brief Returns whether the given file name is inside an archive.
4444
*
45-
* If `NULL` is passed, `false` is returned.
45+
* If @c NULL is passed, @c false is returned.
4646
*
4747
* @param fileName the file name to be checked
4848
* @return whether the file name is inside an archive
4949
*/
5050
static inline bool macho_cache_isInArchive(const char* fileName) {
5151
if (fileName == NULL) return false;
52-
53-
char* lp = strrchr(fileName, '(');
54-
char* rp = strrchr(fileName, ')');
52+
53+
const char* lp = strrchr(fileName, '(');
54+
const char* rp = strrchr(fileName, ')');
5555

5656
return lp != NULL && rp != NULL && lp < rp;
5757
}
5858

5959
/**
6060
* @brief Returns the archive name of the given file name.
6161
*
62-
* The returned string is allocated and needs to be `free`d.
62+
* The returned string is allocated and needs to be freed.
6363
*
6464
* @param fileName the full file name
65-
* @return the archive name or `NULL` if the allocation failed or the given file name is not inside an archive
65+
* @return the archive name or @c NULL if the allocation failed or the given
66+
* file name is not inside an archive
6667
*/
6768
static inline char* macho_cache_getArchiveName(const char* fileName) {
6869
if (fileName == NULL) return NULL;
@@ -80,7 +81,8 @@ static inline char* macho_cache_getArchiveName(const char* fileName) {
8081
}
8182

8283
/**
83-
* The callback function for the archive parser adds the given object file object to the cache.
84+
* The callback function for the archive parser adds the given object file
85+
* object to the cache.
8486
*
8587
* @param file the object file object to be added
8688
*/
@@ -92,7 +94,7 @@ static inline void macho_cache_archiveCallback(struct objectFile* file) {
9294
/**
9395
* @brief Loads the archive of the given file name.
9496
*
95-
* When `NULL` is passed, `false` is returned.
97+
* When @c NULL is passed, @c false is returned.
9698
*
9799
* @param archiveName the file name of the archive to be loaded
98100
* @return whether the archive was loaded successfully
@@ -118,7 +120,7 @@ static inline bool macho_cache_archiveLoaded(const char* archiveName) {
118120
return false;
119121
}
120122

121-
struct objectFile* macho_cache_findOrAdd(const char* fileName, uint64_t lastModified) {
123+
struct objectFile* macho_cache_findOrAdd(const char* fileName, const uint64_t lastModified) {
122124
struct objectFile* it;
123125
for (it = cache.objectFiles; it != NULL && strcmp(it->name, fileName) != 0; it = it->next);
124126

@@ -138,7 +140,7 @@ struct objectFile* macho_cache_findOrAdd(const char* fileName, uint64_t lastModi
138140
return NULL;
139141
}
140142
it->name = strdup(fileName);
141-
it->lastModified = lastModified;
143+
it->lastModified = (time_t) lastModified;
142144
it->next = cache.objectFiles;
143145
cache.objectFiles = it;
144146
}

src/parser/file/macho/cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* CallstackLibrary - Library creating human-readable call stacks.
33
*
4-
* Copyright (C) 2024 mhahnFr
4+
* Copyright (C) 2024 - 2025 mhahnFr
55
*
66
* This file is part of the CallstackLibrary.
77
*
@@ -22,17 +22,17 @@
2222
#ifndef cache_h
2323
#define cache_h
2424

25-
#include <stdbool.h>
2625
#include <stdint.h>
2726

2827
#include "objectFile.h"
2928

3029
/**
31-
* Finds or adds the object file object with the given file name and the given timestamp.
30+
* Finds or adds the object file object with the given file name and the given
31+
* timestamp.
3232
*
3333
* @param fileName the name of the object file
3434
* @param lastModified the timestamp of the last modification
35-
* @return the object file object or `NULL` if unable to allocate
35+
* @return the object file object or @c NULL if unable to allocate
3636
*/
3737
struct objectFile* macho_cache_findOrAdd(const char* fileName, uint64_t lastModified);
3838

0 commit comments

Comments
 (0)