curl-library
Re: lib/strcase.c refactoring
Date: Tue, 1 Nov 2016 23:54:00 +0100 (CET)
On Tue, 1 Nov 2016, Dan Fandrich wrote:
> There's another fallout from commit 95bd2b3e: tool_metalink.c is using
> Curl_raw_toupper for which a public API replacement isn't available, so no
> longer compiling strcase.c to fix the Windows link problem is causing
> Metalink builds to fail.
We can easily avoid the toupper call and frankly simplify that function at the
same time by instead simply using strtol(). Something like this:
--- a/src/tool_metalink.c
+++ b/src/tool_metalink.c
@@ -90,12 +90,10 @@ struct win32_crypto_hash {
# define SHA256_CTX struct win32_crypto_hash
#else
# error "Can't compile METALINK support without a crypto library."
#endif
-#include "strcase.h"
-
#define ENABLE_CURLX_PRINTF
/* use our own printf() functions */
#include "curlx.h"
#include "tool_getparam.h"
@@ -561,22 +559,17 @@ int Curl_digest_final(digest_context *context, unsigned
char *result)
return 0;
}
static unsigned char hex_to_uint(const char *s)
{
- int v[2];
- int i;
- for(i = 0; i < 2; ++i) {
- v[i] = Curl_raw_toupper(s[i]);
- if('0' <= v[i] && v[i] <= '9') {
- v[i] -= '0';
- }
- else if('A' <= v[i] && v[i] <= 'Z') {
- v[i] -= 'A'-10;
- }
- }
- return (unsigned char)((v[0] << 4) | v[1]);
+ char buf[3];
+ long val;
+ buf[0] = s[0];
+ buf[1] = s[1];
+ buf[2] = 0;
+ val = strtol(buf, NULL, 16);
+ return (unsigned char)(val&0xff);
}
/*
* Check checksum of file denoted by filename. The expected hash value
* is given in hex_hash which is hex-encoded string.
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2016-11-01