Commit f7681a59 authored by Yoni Fogel's avatar Yoni Fogel

Fix build due to windows porting

git-svn-id: file:///svn/toku/tokudb@10521 c7de825b-a66e-492c-adef-691d508d4ae1
parent cdcb5a28
...@@ -57,8 +57,7 @@ $(TARGETS_BDB): DLINK_FILES=db.$(SOEXT) ...@@ -57,8 +57,7 @@ $(TARGETS_BDB): DLINK_FILES=db.$(SOEXT)
endif endif
#empty on purpose #empty on purpose
BDB_CPPFLAGS+=-D_GNU_SOURCE -D_SVID_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600 -DBDB -I$(TOKUROOT)toku_include -I$(PORTABILITY_HEADERS) CPPFLAGS+= -D_GNU_SOURCE
TOKUDB=libtokudb.$(SOEXT) TOKUDB=libtokudb.$(SOEXT)
default: build default: build
......
...@@ -45,5 +45,5 @@ else ...@@ -45,5 +45,5 @@ else
endif endif
clean: clean:
rm -rf $(TARGETS) *.valgrind rm -rf $(TARGETS) *.valgrind pwrite4g.data testdir
...@@ -32,7 +32,7 @@ int main(void) { ...@@ -32,7 +32,7 @@ int main(void) {
test_stat("testdir/foo/", -1, ENOENT); test_stat("testdir/foo/", -1, ENOENT);
r = system("touch testdir/foo"); assert(r==0); r = system("touch testdir/foo"); assert(r==0);
test_stat("testdir/foo", 0, 0); test_stat("testdir/foo", 0, 0);
test_stat("testdir/foo/", -1, ENOENT); test_stat("testdir/foo/", -1, ENOTDIR);
test_stat("testdir", 0, 0); test_stat("testdir", 0, 0);
......
...@@ -7,6 +7,7 @@ TOKUROOT=../ ...@@ -7,6 +7,7 @@ TOKUROOT=../
INCLUDEDIRS=-I. -I$(TOKUROOT)toku_include -I$(TOKUROOT)include -I$(TOKUROOT)src INCLUDEDIRS=-I. -I$(TOKUROOT)toku_include -I$(TOKUROOT)include -I$(TOKUROOT)src
DEPEND_COMPILE += \ DEPEND_COMPILE += \
./*.h \ ./*.h \
SKIP_NORETURN=1
#end #end
HERE = utils HERE = utils
...@@ -25,6 +26,7 @@ DIFF=diff -q -I 'db_pagesize=' ...@@ -25,6 +26,7 @@ DIFF=diff -q -I 'db_pagesize='
# vars to compile bins that handle tokudb using libtokudb.a # vars to compile bins that handle tokudb using libtokudb.a
CPPFLAGS+= -D_GNU_SOURCE
# vars to compile bins that handle bdb # vars to compile bins that handle bdb
BDB_CPPFLAGS = -I$(BDBDIR)/include BDB_CPPFLAGS = -I$(BDBDIR)/include
BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb -lpthread $(BDB_LOADLIBES) BDB_LDFLAGS = -L$(BDBDIR)/lib -ldb -lpthread $(BDB_LOADLIBES)
...@@ -40,6 +42,9 @@ STATIC_UTILS=$(patsubst %$(BINSUF),%_static$(BINSUF),$(UTILS)) ...@@ -40,6 +42,9 @@ STATIC_UTILS=$(patsubst %$(BINSUF),%_static$(BINSUF),$(UTILS))
$(UTILS): DLINK_FILES=$(TOKUROOT)lib/libtokudb.$(SOEXT) $(UTILS): DLINK_FILES=$(TOKUROOT)lib/libtokudb.$(SOEXT)
$(STATIC_UTILS): LINK_FILES+=$(TOKUROOT)lib/libtokudb.$(AEXT) $(STATIC_UTILS): LINK_FILES+=$(TOKUROOT)lib/libtokudb.$(AEXT)
$(UTILS) $(STATIC_UTILS): RPATH_DIRS+=$(TOKUROOT)lib
#empty
ifeq ($(OS_CHOICE),windows) ifeq ($(OS_CHOICE),windows)
ifdef BDBDIR ifdef BDBDIR
$(BDB_UTILS): INCLUDEDIRS=-I$(BDBDIR)/include $(BDB_UTILS): INCLUDEDIRS=-I$(BDBDIR)/include
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <db.h> #include <db.h>
#include <inttypes.h> #include <inttypes.h>
#include <signal.h> #include <signal.h>
#include <memory.h>
typedef u_int8_t bool; typedef u_int8_t bool;
......
...@@ -140,7 +140,7 @@ printabletocstring(char* inputstr, char** poutputstr) ...@@ -140,7 +140,7 @@ printabletocstring(char* inputstr, char** poutputstr)
assert(poutputstr); assert(poutputstr);
assert(*poutputstr == NULL); assert(*poutputstr == NULL);
cstring = (char*)malloc((strlen(inputstr) + 1) * sizeof(char)); cstring = (char*)toku_malloc((strlen(inputstr) + 1) * sizeof(char));
if (cstring == NULL) { if (cstring == NULL) {
PRINT_ERROR(errno, "printabletocstring"); PRINT_ERROR(errno, "printabletocstring");
goto error; goto error;
...@@ -200,8 +200,8 @@ verify_library_version() ...@@ -200,8 +200,8 @@ verify_library_version()
static int last_caught = 0; static int last_caught = 0;
static void catch_signal(int signal) { static void catch_signal(int which_signal) {
last_caught = signal; last_caught = which_signal;
if (last_caught == 0) last_caught = SIGINT; if (last_caught == 0) last_caught = SIGINT;
} }
......
...@@ -236,7 +236,6 @@ int create_init_env() ...@@ -236,7 +236,6 @@ int create_init_env()
DB_ENV* dbenv; DB_ENV* dbenv;
int flags; int flags;
//TODO: Experiments to determine right cache size for tokudb, or maybe command line argument. //TODO: Experiments to determine right cache size for tokudb, or maybe command line argument.
int cache = 1 << 20; /* 1 megabyte */
retval = db_env_create(&dbenv, 0); retval = db_env_create(&dbenv, 0);
if (retval) { if (retval) {
...@@ -280,7 +279,6 @@ int create_init_env() ...@@ -280,7 +279,6 @@ int create_init_env()
PRINT_ERROR(retval, "DB_ENV->open"); PRINT_ERROR(retval, "DB_ENV->open");
goto error; goto error;
} }
success:
g.dbenv = dbenv; g.dbenv = dbenv;
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -378,15 +376,15 @@ error: ...@@ -378,15 +376,15 @@ error:
static int dump_dbt(DBT* dbt) static int dump_dbt(DBT* dbt)
{ {
char* str; char* str;
u_int32_t index; u_int32_t idx;
assert(dbt); assert(dbt);
str = (char*)dbt->data; str = (char*)dbt->data;
if (g.leadingspace) printf(" "); if (g.leadingspace) printf(" ");
if (dbt->size > 0) { if (dbt->size > 0) {
assert(dbt->data); assert(dbt->data);
for (index = 0; index < dbt->size; index++) { for (idx = 0; idx < dbt->size; idx++) {
outputbyte(str[index]); outputbyte(str[idx]);
if (ferror(stdout)) { if (ferror(stdout)) {
perror("stdout"); perror("stdout");
goto error; goto error;
...@@ -404,10 +402,8 @@ error: ...@@ -404,10 +402,8 @@ error:
int dump_pairs() int dump_pairs()
{ {
int retval; int retval;
size_t length;
DBT key; DBT key;
DBT data; DBT data;
int spacech;
DB* db = g.db; DB* db = g.db;
DBC* dbc = NULL; DBC* dbc = NULL;
...@@ -438,7 +434,6 @@ cleanup: ...@@ -438,7 +434,6 @@ cleanup:
PRINT_ERROR(retval, "DBC->c_close"); PRINT_ERROR(retval, "DBC->c_close");
g.exitcode = EXIT_FAILURE; g.exitcode = EXIT_FAILURE;
} }
success:
return g.exitcode; return g.exitcode;
} }
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <db.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <db.h>
#if IS_TDB #if IS_TDB
#include <ydb.h> #include <ydb.h>
#endif #endif
......
...@@ -44,7 +44,6 @@ load_globals g; ...@@ -44,7 +44,6 @@ load_globals g;
#include "tokudb_common_funcs.h" #include "tokudb_common_funcs.h"
static int usage (void); static int usage (void);
static int longusage (void);
static int load_database (void); static int load_database (void);
static int create_init_env(void); static int create_init_env(void);
static int read_header (void); static int read_header (void);
...@@ -164,11 +163,11 @@ cleanup: ...@@ -164,11 +163,11 @@ cleanup:
g.exitcode = EXIT_FAILURE; g.exitcode = EXIT_FAILURE;
fprintf(stderr, "%s: dbenv->close: %s\n", g.progname, db_strerror(retval)); fprintf(stderr, "%s: dbenv->close: %s\n", g.progname, db_strerror(retval));
} }
if (g.config_options) free(g.config_options); if (g.config_options) toku_free(g.config_options);
if (g.subdatabase) free(g.subdatabase); if (g.subdatabase) toku_free(g.subdatabase);
if (g.read_header.data) free(g.read_header.data); if (g.read_header.data) toku_free(g.read_header.data);
if (g.get_dbt.data[0]) free(g.get_dbt.data[0]); if (g.get_dbt.data[0]) toku_free(g.get_dbt.data[0]);
if (g.get_dbt.data[1]) free(g.get_dbt.data[1]); if (g.get_dbt.data[1]) toku_free(g.get_dbt.data[1]);
resend_signals(); resend_signals();
return g.exitcode; return g.exitcode;
...@@ -176,7 +175,6 @@ cleanup: ...@@ -176,7 +175,6 @@ cleanup:
int load_database() int load_database()
{ {
DB_ENV* dbenv = g.dbenv;
int retval; int retval;
/* Create a database handle. */ /* Create a database handle. */
...@@ -232,7 +230,7 @@ int create_init_env() ...@@ -232,7 +230,7 @@ int create_init_env()
DB_ENV* dbenv; DB_ENV* dbenv;
int flags; int flags;
//TODO: Experiments to determine right cache size for tokudb, or maybe command line argument. //TODO: Experiments to determine right cache size for tokudb, or maybe command line argument.
int cache = 1 << 20; /* 1 megabyte */ //int cache = 1 << 20; /* 1 megabyte */
retval = db_env_create(&dbenv, 0); retval = db_env_create(&dbenv, 0);
if (retval) { if (retval) {
...@@ -279,7 +277,6 @@ int create_init_env() ...@@ -279,7 +277,6 @@ int create_init_env()
PRINT_ERROR(retval, "DB_ENV->open"); PRINT_ERROR(retval, "DB_ENV->open");
goto error; goto error;
} }
success:
g.dbenv = dbenv; g.dbenv = dbenv;
return EXIT_SUCCESS; return EXIT_SUCCESS;
...@@ -386,26 +383,25 @@ if (!strcmp(field, match)) { \ ...@@ -386,26 +383,25 @@ if (!strcmp(field, match)) { \
int read_header() int read_header()
{ {
static u_int64_t datasize = 1 << 10; static u_int64_t datasize = 1 << 10;
u_int64_t index = 0; u_int64_t idx = 0;
char* field; char* field;
char* value; char* value;
int ch; int ch;
int32_t num; int32_t num;
int retval; int retval;
DB* db = g.db; DB* db = g.db;
DB_ENV* dbenv = g.dbenv;
int r; int r;
assert(g.header); assert(g.header);
if (g.read_header.data == NULL && (g.read_header.data = (char*)malloc(datasize * sizeof(char))) == NULL) { if (g.read_header.data == NULL && (g.read_header.data = (char*)toku_malloc(datasize * sizeof(char))) == NULL) {
PRINT_ERROR(errno, "read_header: malloc"); PRINT_ERROR(errno, "read_header: malloc");
goto error; goto error;
} }
while (!g.eof) { while (!g.eof) {
if (caught_any_signals()) goto success; if (caught_any_signals()) goto success;
g.linenumber++; g.linenumber++;
index = 0; idx = 0;
/* Read a line. */ /* Read a line. */
while (true) { while (true) {
if ((ch = getchar()) == EOF) { if ((ch = getchar()) == EOF) {
...@@ -415,14 +411,14 @@ int read_header() ...@@ -415,14 +411,14 @@ int read_header()
} }
if (ch == '\n') break; if (ch == '\n') break;
g.read_header.data[index] = (char)ch; g.read_header.data[idx] = (char)ch;
index++; idx++;
/* Ensure room exists for next character/null terminator. */ /* Ensure room exists for next character/null terminator. */
if (index == datasize && doublechararray(&g.read_header.data, &datasize)) goto error; if (idx == datasize && doublechararray(&g.read_header.data, &datasize)) goto error;
} }
if (index == 0 && g.eof) goto success; if (idx == 0 && g.eof) goto success;
g.read_header.data[index] = '\0'; g.read_header.data[idx] = '\0';
field = g.read_header.data; field = g.read_header.data;
if ((value = strchr(g.read_header.data, '=')) == NULL) goto formaterror; if ((value = strchr(g.read_header.data, '=')) == NULL) goto formaterror;
...@@ -465,7 +461,7 @@ int read_header() ...@@ -465,7 +461,7 @@ int read_header()
} }
if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) { if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) {
if (g.subdatabase != NULL) { if (g.subdatabase != NULL) {
free(g.subdatabase); toku_free(g.subdatabase);
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
...@@ -497,41 +493,35 @@ int read_header() ...@@ -497,41 +493,35 @@ int read_header()
success: success:
r = 0; r = 0;
if (false) {
printerror:
r = EXIT_FAILURE;
PRINT_ERROR(retval, "%s=%s", field, value);
}
if (false) { if (false) {
formaterror: formaterror:
r = EXIT_FAILURE; r = EXIT_FAILURE;
PRINT_ERRORX("line %"PRIu64": unexpected format", g.linenumber); PRINT_ERRORX("line %"PRIu64": unexpected format", g.linenumber);
} }
if (false) {
error: error:
r = EXIT_FAILURE;
}
return r; return r;
} }
int apply_commandline_options() int apply_commandline_options()
{ {
int r; int r;
char** next_config_option = g.config_options; unsigned idx;
unsigned index;
char* field; char* field;
char* value = NULL; char* value = NULL;
bool first;
int ch;
int32_t num; int32_t num;
int retval; int retval;
DB* db = g.db; DB* db = g.db;
DB_ENV* dbenv = g.dbenv;
for (index = 0; g.config_options[index]; index++) { for (idx = 0; g.config_options[idx]; idx++) {
if (value) { if (value) {
/* Restore the field=value format. */ /* Restore the field=value format. */
value[-1] = '='; value[-1] = '=';
value = NULL; value = NULL;
} }
field = g.config_options[index]; field = g.config_options[idx];
if ((value = strchr(field, '=')) == NULL) { if ((value = strchr(field, '=')) == NULL) {
PRINT_ERRORX("command-line configuration uses name=value format"); PRINT_ERRORX("command-line configuration uses name=value format");
...@@ -547,7 +537,7 @@ int apply_commandline_options() ...@@ -547,7 +537,7 @@ int apply_commandline_options()
if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) { if (!strcmp(field, "database") || !strcmp(field, "subdatabase")) {
if (g.subdatabase != NULL) { if (g.subdatabase != NULL) {
free(g.subdatabase); toku_free(g.subdatabase);
g.subdatabase = NULL; g.subdatabase = NULL;
} }
if ((retval = printabletocstring(value, &g.subdatabase))) { if ((retval = printabletocstring(value, &g.subdatabase))) {
...@@ -583,11 +573,6 @@ int apply_commandline_options() ...@@ -583,11 +573,6 @@ int apply_commandline_options()
} }
r = 0; r = 0;
if (false) {
printerror:
r = EXIT_FAILURE;
PRINT_ERROR(retval, "%s=%s", field, value);
}
error: error:
return r; return r;
} }
...@@ -595,9 +580,7 @@ error: ...@@ -595,9 +580,7 @@ error:
int open_database() int open_database()
{ {
DB* db = g.db; DB* db = g.db;
DB_ENV* dbenv = g.dbenv;
int retval; int retval;
DBTYPE opened_type;
int open_flags = 0; int open_flags = 0;
//TODO: Transaction auto commit stuff //TODO: Transaction auto commit stuff
...@@ -643,8 +626,6 @@ error: ...@@ -643,8 +626,6 @@ error:
int doublechararray(char** pmem, u_int64_t* size) int doublechararray(char** pmem, u_int64_t* size)
{ {
DB_ENV* dbenv = g.dbenv;
assert(pmem); assert(pmem);
assert(size); assert(size);
assert(IS_POWER_OF_2(*size)); assert(IS_POWER_OF_2(*size));
...@@ -655,7 +636,7 @@ int doublechararray(char** pmem, u_int64_t* size) ...@@ -655,7 +636,7 @@ int doublechararray(char** pmem, u_int64_t* size)
PRINT_ERRORX("Line %"PRIu64": Line too long.\n", g.linenumber); PRINT_ERRORX("Line %"PRIu64": Line too long.\n", g.linenumber);
goto error; goto error;
} }
if ((*pmem = (char*)realloc(*pmem, *size)) == NULL) { if ((*pmem = (char*)toku_realloc(*pmem, *size)) == NULL) {
PRINT_ERROR(errno, "doublechararray: realloc"); PRINT_ERROR(errno, "doublechararray: realloc");
goto error; goto error;
} }
...@@ -667,20 +648,18 @@ error: ...@@ -667,20 +648,18 @@ error:
static int get_dbt(DBT* pdbt) static int get_dbt(DBT* pdbt)
{ {
DB_ENV* dbenv = g.dbenv;
/* Need to store a key and value. */ /* Need to store a key and value. */
static u_int64_t datasize[2] = {1 << 10, 1 << 10}; static u_int64_t datasize[2] = {1 << 10, 1 << 10};
static int which = 0; static int which = 0;
char* datum; char* datum;
u_int64_t index = 0; u_int64_t idx = 0;
int highch; int highch;
int lowch; int lowch;
DB* db = g.db;
/* *pdbt should have been memset to 0 before being called. */ /* *pdbt should have been memset to 0 before being called. */
which = 1 - which; which = 1 - which;
if (g.get_dbt.data[which] == NULL && if (g.get_dbt.data[which] == NULL &&
(g.get_dbt.data[which] = (char*)malloc(datasize[which] * sizeof(char))) == NULL) { (g.get_dbt.data[which] = (char*)toku_malloc(datasize[which] * sizeof(char))) == NULL) {
PRINT_ERROR(errno, "get_dbt: malloc"); PRINT_ERROR(errno, "get_dbt: malloc");
goto error; goto error;
} }
...@@ -741,13 +720,13 @@ static int get_dbt(DBT* pdbt) ...@@ -741,13 +720,13 @@ static int get_dbt(DBT* pdbt)
if (nextch == EOF) { if (nextch == EOF) {
break; break;
} }
if (index == datasize[which]) { if (idx == datasize[which]) {
/* Overflow, double the memory. */ /* Overflow, double the memory. */
if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error; if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error;
datum = g.get_dbt.data[which]; datum = g.get_dbt.data[which];
} }
datum[index] = (char)nextch; datum[idx] = (char)nextch;
index++; idx++;
} }
if (firstch == EOF) g.eof = true; if (firstch == EOF) g.eof = true;
} }
...@@ -772,19 +751,19 @@ static int get_dbt(DBT* pdbt) ...@@ -772,19 +751,19 @@ static int get_dbt(DBT* pdbt)
PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch); PRINT_ERRORX("Line %"PRIu64": Unexpected '%c' (non-hex) input.\n", g.linenumber, lowch);
goto error; goto error;
} }
if (index == datasize[which]) { if (idx == datasize[which]) {
/* Overflow, double the memory. */ /* Overflow, double the memory. */
if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error; if (doublechararray(&g.get_dbt.data[which], &datasize[which])) goto error;
datum = g.get_dbt.data[which]; datum = g.get_dbt.data[which];
} }
datum[index] = (char)((hextoint(highch) << 4) | hextoint(lowch)); datum[idx] = (char)((hextoint(highch) << 4) | hextoint(lowch));
index++; idx++;
} }
if (highch == EOF) g.eof = true; if (highch == EOF) g.eof = true;
} }
/* Done reading. */ /* Done reading. */
pdbt->size = index; pdbt->size = idx;
pdbt->data = (void*)datum; pdbt->data = (void*)datum;
return EXIT_SUCCESS; return EXIT_SUCCESS;
error: error:
...@@ -797,7 +776,6 @@ error: ...@@ -797,7 +776,6 @@ error:
static int insert_pair(DBT* key, DBT* data) static int insert_pair(DBT* key, DBT* data)
{ {
DB_ENV* dbenv = g.dbenv;
DB* db = g.db; DB* db = g.db;
int retval = db->put(db, NULL, key, data, g.overwritekeys ? DB_YESOVERWRITE : DB_NOOVERWRITE); int retval = db->put(db, NULL, key, data, g.overwritekeys ? DB_YESOVERWRITE : DB_NOOVERWRITE);
...@@ -813,13 +791,9 @@ error: ...@@ -813,13 +791,9 @@ error:
int read_keys() int read_keys()
{ {
int retval;
size_t length;
DBT key; DBT key;
DBT data; DBT data;
int spacech; int spacech;
DB* db = g.db;
DB_ENV* dbenv = g.dbenv;
char footer[sizeof("ATA=END\n")]; char footer[sizeof("ATA=END\n")];
...@@ -911,7 +885,6 @@ error: ...@@ -911,7 +885,6 @@ error:
int close_database() int close_database()
{ {
DB* db = g.db; DB* db = g.db;
DB_ENV* dbenv = g.dbenv;
int retval; int retval;
assert(db); assert(db);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment