diff options
author | jbj <devnull@localhost> | 2000-12-02 21:53:44 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2000-12-02 21:53:44 +0000 |
commit | 2885f536b6e314734c0c04245d77b9f7bdc76d42 (patch) | |
tree | 1ab8d5ab1cbc20bd1b1da69ba475b80816db2da9 /lib/md5sum.c | |
parent | d7a40e754dc6b0ac07d2185bb5723384065feab5 (diff) | |
download | librpm-tizen-2885f536b6e314734c0c04245d77b9f7bdc76d42.tar.gz librpm-tizen-2885f536b6e314734c0c04245d77b9f7bdc76d42.tar.bz2 librpm-tizen-2885f536b6e314734c0c04245d77b9f7bdc76d42.zip |
Bring header reggions mods back to top of stack.
CVS patchset: 4305
CVS date: 2000/12/02 21:53:44
Diffstat (limited to 'lib/md5sum.c')
-rw-r--r-- | lib/md5sum.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/md5sum.c b/lib/md5sum.c index 7ae359ef5..0bd07dde7 100644 --- a/lib/md5sum.c +++ b/lib/md5sum.c @@ -13,6 +13,7 @@ #include "system.h" #include "md5.h" +#include "rpmio_internal.h" /** * Calculate MD5 sum for file. @@ -23,12 +24,15 @@ * @return 0 on success, 1 on error */ static int domd5(const char * fn, unsigned char * digest, int asAscii, - int brokenEndian) { + int brokenEndian) +{ + int rc; + +#ifndef DYING unsigned char buf[1024]; unsigned char bindigest[16]; FILE * fp; MD5_CTX ctx; - int n; memset(bindigest, 0, sizeof(bindigest)); fp = fopen(fn, "r"); @@ -37,8 +41,8 @@ static int domd5(const char * fn, unsigned char * digest, int asAscii, } rpmMD5Init(&ctx, brokenEndian); - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) - rpmMD5Update(&ctx, buf, n); + while ((rc = fread(buf, sizeof(buf[0]), sizeof(buf), fp)) > 0) + rpmMD5Update(&ctx, buf, rc); rpmMD5Final(bindigest, &ctx); if (ferror(fp)) { fclose(fp); @@ -69,8 +73,37 @@ static int domd5(const char * fn, unsigned char * digest, int asAscii, } fclose(fp); + rc = 0; +#else + FD_t fd = Fopen(fn, "r.ufdio"); + unsigned char buf[BUFSIZ]; + unsigned char * md5sum = NULL; + size_t md5len; + + if (fd == NULL || Ferror(fd)) { + if (fd) + Fclose(fd); + return 1; + } + + /* Preserve legacy "brokenEndian" behavior. */ + fdInitMD5(fd, (brokenEndian ? RPMDIGEST_NATIVE : 0) ); + + while ((rc = Fread(buf, sizeof(buf[0]), sizeof(buf), fd)) > 0) + ; + fdFiniMD5(fd, (void **)&md5sum, &md5len, 1); + + if (Ferror(fd)) + rc = 1; + Fclose(fd); + + if (!rc) + memcpy(digest, md5sum, md5len); + if (md5sum) + free(md5sum); +#endif - return 0; + return rc; } int mdbinfile(const char *fn, unsigned char *bindigest) { |