return NULL;
}
-fingerPrint fpLookup(fingerPrintCache cache,
- const char * dirName, const char * baseName, int scareMemory)
+int fpLookup(fingerPrintCache cache,
+ const char * dirName, const char * baseName, int scareMemory,
+ fingerPrint *fp)
{
char dir[PATH_MAX];
const char * cleanDirName;
size_t cdnl;
char * end; /* points to the '\0' at the end of "buf" */
- fingerPrint fp;
struct stat sb;
char *buf = NULL;
char *cdnbuf = NULL;
cdnl = end - dir;
}
}
- fp.entry = NULL;
- fp.subDir = NULL;
- fp.baseName = NULL;
+
+ memset(fp, 0, sizeof(*fp));
if (cleanDirName == NULL) goto exit; /* XXX can't happen */
buf = xstrdup(cleanDirName);
/* as we're stating paths here, we want to follow symlinks */
cacheHit = cacheContainsDirectory(cache, fpDir, fpHash);
if (cacheHit != NULL) {
- fp.entry = cacheHit;
+ fp->entry = cacheHit;
} else if (!stat(fpDir, &sb)) {
struct fprintCacheEntry_s * newEntry = xmalloc(sizeof(* newEntry));
newEntry->ino = sb.st_ino;
newEntry->dev = sb.st_dev;
newEntry->dirName = xstrdup(fpDir);
- fp.entry = newEntry;
+ fp->entry = newEntry;
rpmFpEntryHashAddHEntry(cache->ht,
- newEntry->dirName, fpHash, fp.entry);
+ newEntry->dirName, fpHash, fp->entry);
}
- if (fp.entry) {
- fp.subDir = cleanDirName + (end - buf);
- if (fp.subDir[0] == '/' && fp.subDir[1] != '\0')
- fp.subDir++;
- if (fp.subDir[0] == '\0' ||
+ if (fp->entry) {
+ fp->subDir = cleanDirName + (end - buf);
+ if (fp->subDir[0] == '/' && fp->subDir[1] != '\0')
+ fp->subDir++;
+ if (fp->subDir[0] == '\0' ||
/* XXX don't bother saving '/' as subdir */
- (fp.subDir[0] == '/' && fp.subDir[1] == '\0'))
- fp.subDir = NULL;
- fp.baseName = baseName;
- if (!scareMemory && fp.subDir != NULL)
- fp.subDir = xstrdup(fp.subDir);
- /* FIX: fp.entry.{dirName,dev,ino} undef @*/
+ (fp->subDir[0] == '/' && fp->subDir[1] == '\0'))
+ fp->subDir = NULL;
+ fp->baseName = baseName;
+ if (!scareMemory && fp->subDir != NULL)
+ fp->subDir = xstrdup(fp->subDir);
goto exit;
}
exit:
free(buf);
free(cdnbuf);
- /* FIX: fp.entry.{dirName,dev,ino} undef @*/
- return fp;
+ /* XXX TODO: failure from eg realpath() should be returned and handled */
+ return 0;
}
unsigned int fpHashFunction(const fingerPrint * fp)
fpList[i].subDir = fpList[i - 1].subDir;
fpList[i].baseName = baseNames[i];
} else {
- fpList[i] = fpLookup(cache, dirNames[dirIndexes[i]], baseNames[i],
- 1);
+ fpLookup(cache,
+ dirNames[dirIndexes[i]], baseNames[i], 1, &fpList[i]);
}
}
}
rstrscat(&link, endbasename+1, "/", NULL);
}
- *fp = fpLookup(fpc, link, fp->baseName, 0);
+ fpLookup(fpc, link, fp->baseName, 0, fp);
free(link);
free(currentsubdir);
* @param dirName leading directory name of file path
* @param baseName base name of file path
* @param scareMemory
- * @return pointer to the finger print associated with a file path.
+ * @retval fp pointer of fingerprint struct to fill out
+ * @return 0 on success
*/
RPM_GNUC_INTERNAL
-fingerPrint fpLookup(fingerPrintCache cache, const char * dirName,
- const char * baseName, int scareMemory);
+int fpLookup(fingerPrintCache cache,
+ const char * dirName, const char * baseName, int scareMemory,
+ fingerPrint *fp);
/**
* Return hash value for a finger print.
*matches = xcalloc(1, sizeof(**matches));
fpc = fpCacheCreate(allMatches->count);
- fp1 = fpLookup(fpc, dirName, baseName, 1);
+ fpLookup(fpc, dirName, baseName, 1, &fp1);
i = 0;
while (i < allMatches->count) {
}
if (!skip) {
- fp2 = fpLookup(fpc, dirNames[dirIndexes[num]],
- baseNames[num], 1);
+ fpLookup(fpc,
+ dirNames[dirIndexes[num]], baseNames[num], 1, &fp2);
if (FP_EQUAL(fp1, fp2)) {
struct dbiIndexItem rec = {
.hdrNum = dbiIndexRecordOffset(allMatches, i),