ports/databases/sqlite/patches/patch-src_test-util_c

51 lines
972 B
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
--- src/test-util.c.orig Wed Dec 21 01:51:05 2005
+++ src/test-util.c Wed Dec 21 01:53:15 2005
@@ -0,0 +1,47 @@
+#include <inttypes.h>
+#include <assert.h>
+#include "test-util.h"
+
+/*
+** Translate a single byte of Hex into an integer.
+*/
+static int hexToInt(int h){
+ if( h>='0' && h<='9' ){
+ return h - '0';
+ }else if( h>='a' && h<='f' ){
+ return h - 'a' + 10;
+ }else if( h>='A' && h<='F' ){
+ return h - 'A' + 10;
+ }else{
+ return 0;
+ }
+}
+
+#if defined(SQLITE_TEST)
+/*
+** Convert text generated by the "%p" conversion format back into
+** a pointer.
+*/
+void *sqliteTextToPtr(const char *z){
+ void *p;
+ uint64_t v;
+ uint32_t v2;
+ if( z[0]=='0' && z[1]=='x' ){
+ z += 2;
+ }
+ v = 0;
+ while( *z ){
+ v = (v<<4) + hexToInt(*z);
+ z++;
+ }
+ if( sizeof(p)==sizeof(v) ){
+ p = *(void**)&v;
+ }else{
+ assert( sizeof(p)==sizeof(v2) );
+ v2 = (uint32_t)v;
+ p = *(void**)&v2;
+ }
+ return p;
+}
+#endif
+