Skip to content

Commit d73a7a7

Browse files
committed
libutil/fname: make the API more cache table centric
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 470b789 commit d73a7a7

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

main/fname.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,31 @@ struct comp {
2424

2525
struct canonFnameCacheTable {
2626
hashTable *table;
27+
const char *cwd;
28+
size_t cwd_len;
2729
char *input_last;
2830
char *return_last;
2931
};
3032

31-
extern struct canonFnameCacheTable *canonFnameCacheTableNew (void)
33+
extern struct canonFnameCacheTable *canonFnameCacheTableNew (const char *cwd)
3234
{
3335
struct canonFnameCacheTable *r = xMalloc (1, struct canonFnameCacheTable);
3436
r->table = hashTableNew (7, hashCstrhash, hashCstreq,
3537
eFree, eFree);
3638
r->input_last = NULL;
3739
r->return_last = NULL;
40+
41+
char *cwd_tmp = eStrdup (cwd);
42+
r->cwd = canonicalizeAbsoluteFileName (cwd_tmp);
43+
eFree (cwd_tmp);
44+
r->cwd_len = strlen (r->cwd);
45+
3846
return r;
3947
}
4048

4149
extern void canonFnameCacheTableDelete (struct canonFnameCacheTable *cache_table)
4250
{
51+
eFree ((void *)cache_table->cwd);
4352
hashTableDelete (cache_table->table);
4453
eFree (cache_table);
4554
}
@@ -220,8 +229,8 @@ static char *canonicalizePathNew(const char *dir, size_t dir_len, const char *re
220229
return r;
221230
}
222231

223-
extern const char *canonicalizeRelativeFileName (const char *cwd, size_t cwd_len, const char *input,
224-
struct canonFnameCacheTable *cache_table)
232+
extern const char *canonicalizeRelativeFileName (struct canonFnameCacheTable *cache_table,
233+
const char *input)
225234
{
226235
if (cache_table->input_last)
227236
{
@@ -234,7 +243,7 @@ extern const char *canonicalizeRelativeFileName (const char *cwd, size_t cwd_len
234243
if (r)
235244
return r;
236245

237-
r = canonicalizePathNew (cwd, cwd_len, input);
246+
r = canonicalizePathNew (cache_table->cwd, cache_table->cwd_len, input);
238247

239248
cache_table->input_last = eStrdup (input);
240249
cache_table->return_last = r;

main/fname.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include "htable.h"
1313

1414
struct canonFnameCacheTable;
15-
extern struct canonFnameCacheTable *canonFnameCacheTableNew (void);
15+
extern struct canonFnameCacheTable *canonFnameCacheTableNew (const char *cwd);
1616
extern void canonFnameCacheTableDelete (struct canonFnameCacheTable *cache_table);
1717

1818
/* Don't free the cstring returned from this function directly.
1919
* This function stores the cstring to the cache.
2020
*/
21-
extern const char *canonicalizeRelativeFileName(const char *cwd, size_t cwd_len, const char *input,
22-
struct canonFnameCacheTable *cache_table);
21+
extern const char *canonicalizeRelativeFileName(struct canonFnameCacheTable *cache_table,
22+
const char *input);
2323

2424
/*
2525
* Resolve '.', '..', and '//' in FNAME as if the current working

0 commit comments

Comments
 (0)