mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-11-01 03:48:57 +08:00 
			
		
		
		
	mdbx: cleanup tools from Windows.
Change-Id: I8c226a866dbc7081e57af3d6ec687b9cbea2684f
This commit is contained in:
		| @@ -11,12 +11,6 @@ | |||||||
|  * top-level directory of the distribution or, alternatively, at |  * top-level directory of the distribution or, alternatively, at | ||||||
|  * <http://www.OpenLDAP.org/license.html>. |  * <http://www.OpenLDAP.org/license.html>. | ||||||
|  */ |  */ | ||||||
| #ifdef _WIN32 |  | ||||||
| #include <windows.h> |  | ||||||
| #define	MDB_STDOUT	GetStdHandle(STD_OUTPUT_HANDLE) |  | ||||||
| #else |  | ||||||
| #define	MDB_STDOUT	1 |  | ||||||
| #endif |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <signal.h> | #include <signal.h> | ||||||
| @@ -70,7 +64,7 @@ int main(int argc,char * argv[]) | |||||||
| 	if (rc == MDB_SUCCESS) { | 	if (rc == MDB_SUCCESS) { | ||||||
| 		act = "copying"; | 		act = "copying"; | ||||||
| 		if (argc == 2) | 		if (argc == 2) | ||||||
| 			rc = mdb_env_copyfd2(env, MDB_STDOUT, cpflags); | 			rc = mdb_env_copyfd2(env, STDOUT_FILENO, cpflags); | ||||||
| 		else | 		else | ||||||
| 			rc = mdb_env_copy2(env, argv[2], cpflags); | 			rc = mdb_env_copy2(env, argv[2], cpflags); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -20,12 +20,6 @@ | |||||||
| #include <signal.h> | #include <signal.h> | ||||||
| #include "mdbx.h" | #include "mdbx.h" | ||||||
|  |  | ||||||
| #ifdef _WIN32 |  | ||||||
| #define Z	"I" |  | ||||||
| #else |  | ||||||
| #define Z	"z" |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #define PRINT	1 | #define PRINT	1 | ||||||
| static int mode; | static int mode; | ||||||
|  |  | ||||||
| @@ -116,7 +110,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name) | |||||||
| 	if (name) | 	if (name) | ||||||
| 		printf("database=%s\n", name); | 		printf("database=%s\n", name); | ||||||
| 	printf("type=btree\n"); | 	printf("type=btree\n"); | ||||||
| 	printf("mapsize=%" Z "u\n", info.me_mapsize); | 	printf("mapsize=%zu\n", info.me_mapsize); | ||||||
| 	if (info.me_mapaddr) | 	if (info.me_mapaddr) | ||||||
| 		printf("mapaddr=%p\n", info.me_mapaddr); | 		printf("mapaddr=%p\n", info.me_mapaddr); | ||||||
| 	printf("maxreaders=%u\n", info.me_maxreaders); | 	printf("maxreaders=%u\n", info.me_maxreaders); | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								mdb_load.c
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								mdb_load.c
									
									
									
									
									
								
							| @@ -38,12 +38,6 @@ static MDB_envinfo info; | |||||||
|  |  | ||||||
| static MDB_val kbuf, dbuf; | static MDB_val kbuf, dbuf; | ||||||
|  |  | ||||||
| #ifdef _WIN32 |  | ||||||
| #define Z	"I" |  | ||||||
| #else |  | ||||||
| #define Z	"z" |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| #define STRLENOF(s)	(sizeof(s)-1) | #define STRLENOF(s)	(sizeof(s)-1) | ||||||
|  |  | ||||||
| typedef struct flagbit { | typedef struct flagbit { | ||||||
| @@ -78,7 +72,7 @@ static void readhdr(void) | |||||||
| 		} else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { | 		} else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) { | ||||||
| 			version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); | 			version=atoi((char *)dbuf.mv_data+STRLENOF("VERSION=")); | ||||||
| 			if (version > 3) { | 			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); | 					prog, lineno, version); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -88,7 +82,7 @@ static void readhdr(void) | |||||||
| 			if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) | 			if (!strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "print", STRLENOF("print"))) | ||||||
| 				mode |= PRINT; | 				mode |= PRINT; | ||||||
| 			else if (strncmp((char *)dbuf.mv_data+STRLENOF("FORMAT="), "bytevalue", STRLENOF("bytevalue"))) { | 			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=")); | 					prog, lineno, (char *)dbuf.mv_data+STRLENOF("FORMAT=")); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -99,7 +93,7 @@ static void readhdr(void) | |||||||
| 			subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); | 			subname = strdup((char *)dbuf.mv_data+STRLENOF("database=")); | ||||||
| 		} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { | 		} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) { | ||||||
| 			if (strncmp((char *)dbuf.mv_data+STRLENOF("type="), "btree", STRLENOF("btree")))  { | 			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=")); | 					prog, lineno, (char *)dbuf.mv_data+STRLENOF("type=")); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -109,7 +103,7 @@ static void readhdr(void) | |||||||
| 			if (ptr) *ptr = '\0'; | 			if (ptr) *ptr = '\0'; | ||||||
| 			i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); | 			i = sscanf((char *)dbuf.mv_data+STRLENOF("mapaddr="), "%p", &info.me_mapaddr); | ||||||
| 			if (i != 1) { | 			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=")); | 					prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapaddr=")); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -117,9 +111,9 @@ static void readhdr(void) | |||||||
| 			int i; | 			int i; | ||||||
| 			ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); | 			ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size); | ||||||
| 			if (ptr) *ptr = '\0'; | 			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) { | 			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=")); | 					prog, lineno, (char *)dbuf.mv_data+STRLENOF("mapsize=")); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -129,7 +123,7 @@ static void readhdr(void) | |||||||
| 			if (ptr) *ptr = '\0'; | 			if (ptr) *ptr = '\0'; | ||||||
| 			i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); | 			i = sscanf((char *)dbuf.mv_data+STRLENOF("maxreaders="), "%u", &info.me_maxreaders); | ||||||
| 			if (i != 1) { | 			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=")); | 					prog, lineno, (char *)dbuf.mv_data+STRLENOF("maxreaders=")); | ||||||
| 				exit(EXIT_FAILURE); | 				exit(EXIT_FAILURE); | ||||||
| 			} | 			} | ||||||
| @@ -146,12 +140,12 @@ static void readhdr(void) | |||||||
| 			if (!dbflags[i].bit) { | 			if (!dbflags[i].bit) { | ||||||
| 				ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); | 				ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size); | ||||||
| 				if (!ptr) { | 				if (!ptr) { | ||||||
| 					fprintf(stderr, "%s: line %" Z "d: unexpected format\n", | 					fprintf(stderr, "%s: line %zd: unexpected format\n", | ||||||
| 						prog, lineno); | 						prog, lineno); | ||||||
| 					exit(EXIT_FAILURE); | 					exit(EXIT_FAILURE); | ||||||
| 				} else { | 				} else { | ||||||
| 					*ptr = '\0'; | 					*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); | 						prog, lineno, (char *)dbuf.mv_data); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @@ -161,7 +155,7 @@ static void readhdr(void) | |||||||
|  |  | ||||||
| static void badend(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); | 		prog, lineno); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -219,7 +213,7 @@ badend: | |||||||
| 		buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); | 		buf->mv_data = realloc(buf->mv_data, buf->mv_size*2); | ||||||
| 		if (!buf->mv_data) { | 		if (!buf->mv_data) { | ||||||
| 			Eof = 1; | 			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); | 				prog, lineno); | ||||||
| 			return EOF; | 			return EOF; | ||||||
| 		} | 		} | ||||||
| @@ -404,7 +398,7 @@ int main(int argc, char *argv[]) | |||||||
|  |  | ||||||
| 			rc = readline(&data, &dbuf); | 			rc = readline(&data, &dbuf); | ||||||
| 			if (rc) { | 			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; | 				goto txn_abort; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| @@ -419,7 +413,7 @@ int main(int argc, char *argv[]) | |||||||
| 			if (batch == 100) { | 			if (batch == 100) { | ||||||
| 				rc = mdb_txn_commit(txn); | 				rc = mdb_txn_commit(txn); | ||||||
| 				if (rc) { | 				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)); | 						prog, lineno, mdb_strerror(rc)); | ||||||
| 					goto env_close; | 					goto env_close; | ||||||
| 				} | 				} | ||||||
| @@ -439,7 +433,7 @@ int main(int argc, char *argv[]) | |||||||
| 		rc = mdb_txn_commit(txn); | 		rc = mdb_txn_commit(txn); | ||||||
| 		txn = NULL; | 		txn = NULL; | ||||||
| 		if (rc) { | 		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)); | 				prog, lineno, mdb_strerror(rc)); | ||||||
| 			goto env_close; | 			goto env_close; | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user