Commit 4ed90cab authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get rid of fmemopen. Fixes #446.

git-svn-id: file:///svn/tokudb@2408 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5f07bbf7
//NOTE: fmemopen does not exist in OSX
// I want fmemopen
#define _GNU_SOURCE
#include <assert.h> #include <assert.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>
#include "test.h" #include "test.h"
char const* expect_errpfx; char const* expect_errpfx;
...@@ -39,43 +36,56 @@ int main (int argc, const char *argv[]) { ...@@ -39,43 +36,56 @@ int main (int argc, const char *argv[]) {
for (do_errpfx=0; do_errpfx<2; do_errpfx++) { for (do_errpfx=0; do_errpfx<2; do_errpfx++) {
for (do_errfile=0; do_errfile<2; do_errfile++) { for (do_errfile=0; do_errfile<2; do_errfile++) {
for (do_errcall=0; do_errcall<2; do_errcall++) { for (do_errcall=0; do_errcall<2; do_errcall++) {
DB_ENV *env; char errfname[] = __FILE__ ".errs";
char buf[10000]=""; unlink(errfname);
FILE *write_here = fmemopen(buf, sizeof(buf), "w"); {
n_handle_error=0; DB_ENV *env;
r = db_env_create(&env, 0); assert(r==0); FILE *write_here = fopen(errfname, "w");
if (do_errpfx) { assert(write_here);
expect_errpfx="whoopi"; n_handle_error=0;
env->set_errpfx(env, expect_errpfx); r = db_env_create(&env, 0); assert(r==0);
} else {
expect_errpfx=0;
}
env->set_errfile(env,0); // Turn off those annoying errors
if (do_errfile)
env->set_errfile(env, write_here);
if (do_errcall)
env->set_errcall(env, handle_error);
r = env->open(env, DIR, -1, 0644);
assert(r==EINVAL);
r = env->close(env, 0); assert(r==0);
fclose(write_here);
if (do_errfile) {
printf("buf=%s(end of buf)\n", buf);
if (do_errpfx) { if (do_errpfx) {
assert(strncmp(buf,"whoopi:",6)==0); expect_errpfx="whoopi";
env->set_errpfx(env, expect_errpfx);
} else { } else {
assert(buf[0]!=0); expect_errpfx=0;
assert(buf[0]!=':');
} }
assert(buf[strlen(buf)-1]=='\n'); env->set_errfile(env,0); // Turn off those annoying errors
} else { if (do_errfile)
assert(buf[0]==0); env->set_errfile(env, write_here);
if (do_errcall)
env->set_errcall(env, handle_error);
r = env->open(env, DIR, -1, 0644);
assert(r==EINVAL);
r = env->close(env, 0); assert(r==0);
fclose(write_here);
} }
if (do_errcall) { {
assert(n_handle_error==1); FILE *read_here = fopen(errfname, "r");
} else { assert(read_here);
assert(n_handle_error==0); char buf[10000];
int buflen = fread(buf, 1, sizeof(buf)-1, read_here);
assert(buflen>=0);
buf[buflen]=0;
if (do_errfile) {
printf("buf=%s(end of buf)\n", buf);
if (do_errpfx) {
assert(strncmp(buf,"whoopi:",6)==0);
} else {
assert(buf[0]!=0);
assert(buf[0]!=':');
}
assert(buf[strlen(buf)-1]=='\n');
} else {
assert(buf[0]==0);
}
if (do_errcall) {
assert(n_handle_error==1);
} else {
assert(n_handle_error==0);
}
} }
unlink(errfname);
} }
} }
} }
......
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