lib/depends.c: Fix minor memory leak.
[platform/upstream/rpm.git] / lib / fprint.h
1 #ifndef H_FINGERPRINT
2 #define H_FINGERPRINT
3
4 #include "hash.h"
5 #include "header.h"
6
7 /* This is really a directory and symlink cache. We don't differentiate between
8    the two. We can prepopulate it, which allows us to easily conduct "fake"
9    installs of a system w/o actually mounting filesystems. */
10 struct fprintCacheEntry_s {
11     char * dirName;
12     dev_t dev;
13     ino_t ino;
14     int isFake;
15 };
16
17 typedef struct fprintCache_s {
18     hashTable ht;                   /* hashed by dirName */
19 } * fingerPrintCache;
20
21 typedef struct fingerprint_s {
22     const struct fprintCacheEntry_s * entry;
23     const char * subDir;
24     const char * baseName;
25 } fingerPrint;
26
27 /* only if !scarceMemory */
28 #define fpFree(a) free((void *)(a).baseName)
29
30 #define FP_EQUAL(a, b) ((&(a) == &(b)) || \
31                                (((a).entry == (b).entry) && \
32                                 !strcmp((a).subDir, (b).subDir) && \
33                                 !strcmp((a).baseName, (b).baseName)))
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
40 fingerPrintCache fpCacheCreate(int sizeHint);
41 void fpCacheFree(fingerPrintCache cache);
42 fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
43                         const char * baseName, int scareMemory);
44
45 /* Hash based on dev and inode only! */
46 unsigned int fpHashFunction(const void * key);
47 /* exactly equivalent to FP_EQUAL */
48 int fpEqual(const void * key1, const void * key2);
49
50 /* scareMemory is assumed for both of these! */
51 void fpLookupList(fingerPrintCache cache, const char ** dirNames, 
52                   const char ** baseNames, const int * dirIndexes, 
53                   int fileCount, fingerPrint * fpList);
54 void fpLookupHeader(fingerPrintCache cache, Header h, fingerPrint * fpList);
55
56 #ifdef __cplusplus
57 }
58 #endif
59
60 #endif