From daba18111be8c973639908cb88c50b76f6f87bf6 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 30 May 2016 16:27:59 +0300 Subject: [PATCH] mdbx: cleanup tools from Windows. Change-Id: I8c226a866dbc7081e57af3d6ec687b9cbea2684f --- mdb_copy.c | 8 +------- mdb_dump.c | 8 +------- mdb_load.c | 34 ++++++++++++++-------------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/mdb_copy.c b/mdb_copy.c index 8de6fb5f..348bea9e 100644 --- a/mdb_copy.c +++ b/mdb_copy.c @@ -11,12 +11,6 @@ * top-level directory of the distribution or, alternatively, at * . */ -#ifdef _WIN32 -#include -#define MDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE) -#else -#define MDB_STDOUT 1 -#endif #include #include #include @@ -70,7 +64,7 @@ int main(int argc,char * argv[]) if (rc == MDB_SUCCESS) { act = "copying"; if (argc == 2) - rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags); + rc = mdb_env_copyfd2(env, STDOUT_FILENO, cpflags); else rc = mdb_env_copy2(env, argv[2], cpflags); } diff --git a/mdb_dump.c b/mdb_dump.c index e5e0c12c..aeb57801 100644 --- a/mdb_dump.c +++ b/mdb_dump.c @@ -20,12 +20,6 @@ #include #include "mdbx.h" -#ifdef _WIN32 -#define Z "I" -#else -#define Z "z" -#endif - #define PRINT 1 static int mode; @@ -116,7 +110,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name) if (name) printf("database=%s\n", name); printf("type=btree\n"); - printf("mapsize=%" Z "u\n", info.me_mapsize); + printf("mapsize=%zu\n", info.me_mapsize); if (info.me_mapaddr) printf("mapaddr=%p\n", info.me_mapaddr); printf("maxreaders=%u\n", info.me_maxreaders); diff --git a/mdb_load.c b/mdb_load.c index 3b11e541..a883e011 100644 --- a/mdb_load.c +++ b/mdb_load.c @@ -38,12 +38,6 @@ static MDB_envinfo info; static MDB_val kbuf, dbuf; -#ifdef _WIN32 -#define Z "I" -#else -#define Z "z" -#endif - #define STRLENOF(s) (sizeof(s)-1) typedef struct flagbit { @@ -78,7 +72,7 @@ static void readhdr(void) } else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); if (version > 3) { - fprintf(stderr, "%s: line %" Z "d: unsupported VERSION %d\n", + fprintf(stderr, "%s: line %zd: unsupported VERSION %d\n", prog, lineno, version); exit(EXIT_FAILURE); } @@ -88,7 +82,7 @@ static void readhdr(void) if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) mode |= PRINT; else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) { - fprintf(stderr, "%s: line %" Z "d: unsupported FORMAT %s\n", + fprintf(stderr, "%s: line %zd: unsupported FORMAT %s\n", prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT=")); exit(EXIT_FAILURE); } @@ -99,7 +93,7 @@ static void readhdr(void) subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); } else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree"))) { - fprintf(stderr, "%s: line %" Z "d: unsupported type %s\n", + fprintf(stderr, "%s: line %zd: unsupported type %s\n", prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); exit(EXIT_FAILURE); } @@ -109,7 +103,7 @@ static void readhdr(void) if (ptr) *ptr = '\0'; i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); if (i != 1) { - fprintf(stderr, "%s: line %" Z "d: invalid mapaddr %s\n", + fprintf(stderr, "%s: line %zd: invalid mapaddr %s\n", prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr=")); exit(EXIT_FAILURE); } @@ -117,9 +111,9 @@ static void readhdr(void) int i; ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); if (ptr) *ptr = '\0'; - i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%" Z "u", &info.me_mapsize); + i = sscanf((char *)dbuf.mv_data+STRLENOF("mapsize="), "%zu", &info.me_mapsize); if (i != 1) { - fprintf(stderr, "%s: line %" Z "d: invalid mapsize %s\n", + fprintf(stderr, "%s: line %zd: invalid mapsize %s\n", prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize=")); exit(EXIT_FAILURE); } @@ -129,7 +123,7 @@ static void readhdr(void) if (ptr) *ptr = '\0'; i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); if (i != 1) { - fprintf(stderr, "%s: line %" Z "d: invalid maxreaders %s\n", + fprintf(stderr, "%s: line %zd: invalid maxreaders %s\n", prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders=")); exit(EXIT_FAILURE); } @@ -146,12 +140,12 @@ static void readhdr(void) if (!dbflags[i].bit) { ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); if (!ptr) { - fprintf(stderr, "%s: line %" Z "d: unexpected format\n", + fprintf(stderr, "%s: line %zd: unexpected format\n", prog, lineno); exit(EXIT_FAILURE); } else { *ptr = '\0'; - fprintf(stderr, "%s: line %" Z "d: unrecognized keyword ignored: %s\n", + fprintf(stderr, "%s: line %zd: unrecognized keyword ignored: %s\n", prog, lineno, (char *)dbuf.mv_data); } } @@ -161,7 +155,7 @@ static void readhdr(void) static void badend(void) { - fprintf(stderr, "%s: line %" Z "d: unexpected end of input\n", + fprintf(stderr, "%s: line %zd: unexpected end of input\n", prog, lineno); } @@ -219,7 +213,7 @@ badend: buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); if (!buf->mv_data) { Eof = 1; - fprintf(stderr, "%s: line %" Z "d: out of memory, line too long\n", + fprintf(stderr, "%s: line %zd: out of memory, line too long\n", prog, lineno); return EOF; } @@ -404,7 +398,7 @@ int main(int argc, char *argv[]) rc = readline(&data, &dbuf); if (rc) { - fprintf(stderr, "%s: line %" Z "d: failed to read key value\n", prog, lineno); + fprintf(stderr, "%s: line %zd: failed to read key value\n", prog, lineno); goto txn_abort; } @@ -419,7 +413,7 @@ int main(int argc, char *argv[]) if (batch == 100) { rc = mdb_txn_commit(txn); if (rc) { - fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", + fprintf(stderr, "%s: line %zd: txn_commit: %s\n", prog, lineno, mdb_strerror(rc)); goto env_close; } @@ -439,7 +433,7 @@ int main(int argc, char *argv[]) rc = mdb_txn_commit(txn); txn = NULL; if (rc) { - fprintf(stderr, "%s: line %" Z "d: txn_commit: %s\n", + fprintf(stderr, "%s: line %zd: txn_commit: %s\n", prog, lineno, mdb_strerror(rc)); goto env_close; }