diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2012-09-06 12:53:05 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2012-09-06 12:53:05 +0300 |
commit | cffdbc7aec75d4688f84d92609e823a9a38415c4 (patch) | |
tree | 4266a05b1ec9e1cbf7976857c6d85a4c2bf94e14 /lib/fprint.c | |
parent | 1cbc2a14f2731a55e041253bcd9322407a9fd258 (diff) | |
download | librpm-tizen-cffdbc7aec75d4688f84d92609e823a9a38415c4.tar.gz librpm-tizen-cffdbc7aec75d4688f84d92609e823a9a38415c4.tar.bz2 librpm-tizen-cffdbc7aec75d4688f84d92609e823a9a38415c4.zip |
Return fingerprint lookups through retval pointer, not struct
- Returning structs by value is a bit icky, pass in a fp pointer
for fpLookup() to fill in instead. This leaves the actual return code
free for handling errors (but ignoring that for now as we always have)
The other option would be always mallocing the return, and we dont
want to do that...
- Shouldn't change any actual functionality.
Diffstat (limited to 'lib/fprint.c')
-rw-r--r-- | lib/fprint.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/lib/fprint.c b/lib/fprint.c index a579f6f1f..261ad039b 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -62,14 +62,14 @@ static const struct fprintCacheEntry_s * cacheContainsDirectory( 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; @@ -117,9 +117,8 @@ fingerPrint fpLookup(fingerPrintCache cache, 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); @@ -139,31 +138,30 @@ fingerPrint fpLookup(fingerPrintCache cache, /* 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; } @@ -182,8 +180,8 @@ fingerPrint fpLookup(fingerPrintCache cache, 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) @@ -227,8 +225,8 @@ void fpLookupList(fingerPrintCache cache, const char ** dirNames, 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]); } } } @@ -290,7 +288,7 @@ void fpLookupSubdir(rpmFpHash symlinks, rpmFpHash fphash, fingerPrintCache fpc, rstrscat(&link, endbasename+1, "/", NULL); } - *fp = fpLookup(fpc, link, fp->baseName, 0); + fpLookup(fpc, link, fp->baseName, 0, fp); free(link); free(currentsubdir); |