diff options
author | Tim Potter <tpot@samba.org> | 2003-01-21 05:01:05 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2003-01-21 05:01:05 +0000 |
commit | 4d6535dc1a590579585d39d7d3673296844c96ee (patch) | |
tree | bd65bfa6c6d2c32f003802c1dd03a72259a26a84 /source3 | |
parent | 7b69c6a48c088f1abfa0488d655406f405d930eb (diff) | |
download | samba-4d6535dc1a590579585d39d7d3673296844c96ee.tar.gz samba-4d6535dc1a590579585d39d7d3673296844c96ee.tar.bz2 samba-4d6535dc1a590579585d39d7d3673296844c96ee.zip |
Make the valstr and timeout return pointers optional so a caller can
pass NULL if it doesn't care about the gencache key.
(This used to be commit 9ff4fe7e0d95c0cea94f65c00fea21600308d7d1)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/gencache.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index d0748456f9..a844d8c014 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -233,7 +233,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) TDB_DATA keybuf, databuf; /* fail completely if get null pointers passed */ - SMB_ASSERT(keystr && valstr && timeout); + SMB_ASSERT(keystr); if (!gencache_init()) return False; @@ -244,21 +244,42 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) { char* entry_buf = strndup(databuf.dptr, databuf.dsize); - *valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN)); + char *v; + time_t t; + + v = (char*)malloc(sizeof(char) * + (databuf.dsize - TIMEOUT_LEN)); SAFE_FREE(databuf.dptr); - sscanf(entry_buf, CACHE_DATA_FMT, (int*)timeout, *valstr); + sscanf(entry_buf, CACHE_DATA_FMT, (int*)&t, v); SAFE_FREE(entry_buf); - DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, timeout = %s\n", - *timeout > time(NULL) ? "valid" : "expired", keystr, *valstr, - ctime(timeout))); - return *timeout > time(NULL); + DEBUG(10, ("Returning %s cache entry: key = %s, value = %s, " + "timeout = %s\n", t > time(NULL) ? "valid" : + "expired", keystr, v, ctime(&t))); + + if (valstr) + *valstr = v; + else + SAFE_FREE(v); + + if (timeout) + *timeout = t; + + return t > time(NULL); + } else { SAFE_FREE(databuf.dptr); - *valstr = NULL; - timeout = NULL; - DEBUG(10, ("Cache entry with key = %s couldn't be found\n", keystr)); + + if (valstr) + *valstr = NULL; + + if (timeout) + timeout = NULL; + + DEBUG(10, ("Cache entry with key = %s couldn't be found\n", + keystr)); + return False; } } @@ -322,4 +343,3 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time tdb_search_list_free(first_node); } - |