From 2bb4618fa107dc6b02a4eb64e42d0021eca2a9e9 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 8 Apr 2008 12:35:36 +0300 Subject: [PATCH] Eliminate four copy-paste versions of nibble(), stick to rpmstring.h - the one in signature.c wasn't even used... --- lib/query.c | 20 ++------------------ lib/rpmfi.c | 18 +----------------- lib/signature.c | 16 ---------------- rpmdb/rpmdb.c | 20 ++------------------ rpmio/rpmstring.h | 16 ++++++++++++++++ 5 files changed, 21 insertions(+), 69 deletions(-) diff --git a/lib/query.c b/lib/query.c index 20068af..8791c37 100644 --- a/lib/query.c +++ b/lib/query.c @@ -390,22 +390,6 @@ int rpmcliShowMatches(QVA_t qva, rpmts ts) return ec; } -/** - * Convert hex to binary nibble. - * @param c hex character - * @return binary nibble - */ -static inline unsigned char nibble(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A') + 10; - if (c >= 'a' && c <= 'f') - return (c - 'a') + 10; - return 0; -} - /* LCL: segfault (realpath annotation?) */ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg) { @@ -473,7 +457,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg) MD5[0] = '\0'; for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2) - *t = (nibble(s[0]) << 4) | nibble(s[1]); + *t = (rnibble(s[0]) << 4) | rnibble(s[1]); qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_SIGMD5, MD5, sizeof(MD5)); if (qva->qva_mi == NULL) { @@ -514,7 +498,7 @@ int rpmQueryVerify(QVA_t qva, rpmts ts, const char * arg) MD5[0] = '\0'; for (i = 0, t = MD5, s = arg; i < 16; i++, t++, s += 2) - *t = (nibble(s[0]) << 4) | nibble(s[1]); + *t = (rnibble(s[0]) << 4) | rnibble(s[1]); qva->qva_mi = rpmtsInitIterator(ts, RPMTAG_FILEMD5S, MD5, sizeof(MD5)); if (qva->qva_mi == NULL) { diff --git a/lib/rpmfi.c b/lib/rpmfi.c index ab979f9..5905b4d 100644 --- a/lib/rpmfi.c +++ b/lib/rpmfi.c @@ -1111,22 +1111,6 @@ fprintf(stderr, "*** fi %p\t%s[%d]\n", fi, fi->Type, fi->fc); return NULL; } -/** - * Convert hex to binary nibble. - * @param c hex character - * @return binary nibble - */ -static inline unsigned char nibble(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A') + 10; - if (c >= 'a' && c <= 'f') - return (c - 'a') + 10; - return 0; -} - #define _fdupe(_fi, _data) \ if ((_fi)->_data != NULL) \ (_fi)->_data = memcpy(xmalloc((_fi)->fc * sizeof(*(_fi)->_data)), \ @@ -1253,7 +1237,7 @@ if (fi->actions == NULL) continue; } for (j = 0; j < 16; j++, t++, fmd5 += 2) - *t = (nibble(fmd5[0]) << 4) | nibble(fmd5[1]); + *t = (rnibble(fmd5[0]) << 4) | rnibble(fmd5[1]); } fi->fmd5s = hfd(fi->fmd5s, RPM_FORCEFREE_TYPE); } diff --git a/lib/signature.c b/lib/signature.c index 787448c..bbcaba6 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -1070,22 +1070,6 @@ exit: } /** - * Convert hex to binary nibble. - * @param c hex character - * @return binary nibble - */ -static inline unsigned char nibble(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A') + 10; - if (c >= 'a' && c <= 'f') - return (c - 'a') + 10; - return 0; -} - -/** * Verify RSA signature. * @param ts transaction set * @retval msg rbose success/failure text diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index d00cdfa..6f96ade 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -87,22 +87,6 @@ static inline pbm_set * PBM_REALLOC(pbm_set ** sp, int * odp, int nd) return *sp; } -/** - * Convert hex to binary nibble. - * @param c hex character - * @return binary nibble - */ -static inline unsigned char nibble(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A') + 10; - if (c >= 'a' && c <= 'f') - return (c - 'a') + 10; - return 0; -} - #ifdef DYING /** * Check key for printable characters. @@ -2574,7 +2558,7 @@ if (dbiByteSwapped(dbi) == 1) s = rpmvals[i]; t = bin; for (j = 0; j < 16; j++, t++, s += 2) - *t = (nibble(s[0]) << 4) | nibble(s[1]); + *t = (rnibble(s[0]) << 4) | rnibble(s[1]); key->data = bin; key->size = 16; break; @@ -2977,7 +2961,7 @@ data->size = 0; s = rpmvals[i]; t = bin; for (j = 0; j < 16; j++, t++, s += 2) - *t = (nibble(s[0]) << 4) | nibble(s[1]); + *t = (rnibble(s[0]) << 4) | rnibble(s[1]); key->data = bin; key->size = 16; break; diff --git a/rpmio/rpmstring.h b/rpmio/rpmstring.h index cb8bc7a..5b8af0c 100644 --- a/rpmio/rpmstring.h +++ b/rpmio/rpmstring.h @@ -77,6 +77,22 @@ static inline int rtoupper(int c) { return ((rislower(c)) ? (c & ~('a' - 'A')) : c); } +/** + * Convert hex to binary nibble. + * @param c hex character + * @return binary nibble + */ +static inline unsigned char rnibble(char c) +{ + if (c >= '0' && c <= '9') + return (c - '0'); + if (c >= 'A' && c <= 'F') + return (c - 'A') + 10; + if (c >= 'a' && c <= 'f') + return (c - 'a') + 10; + return 0; +} + /** \ingroup rpmstring * Locale insensitive strcasecmp(3). */ -- 2.7.4