0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifdef _WIN32
0015 #include <windows.h>
0016 #define EDB_STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
0017 #else
0018 #define EDB_STDOUT 1
0019 #endif
0020 #include <stdio.h>
0021 #include <stdlib.h>
0022 #include <signal.h>
0023 #include "exdb.h"
0024
0025 static void
0026 sighandle(int sig)
0027 {
0028 }
0029
0030 int main(int argc,char * argv[])
0031 {
0032 int rc;
0033 EDB_env *env;
0034 const char *progname = argv[0], *act;
0035 unsigned flags = EDB_RDONLY;
0036 unsigned cpflags = 0;
0037
0038 for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
0039 if (argv[1][1] == 'n' && argv[1][2] == '\0')
0040 flags |= EDB_NOSUBDIR;
0041 else if (argv[1][1] == 'v' && argv[1][2] == '\0')
0042 flags |= EDB_PREVSNAPSHOT;
0043 else if (argv[1][1] == 'c' && argv[1][2] == '\0')
0044 cpflags |= EDB_CP_COMPACT;
0045 else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
0046 printf("%s\n", EDB_VERSION_STRING);
0047 exit(0);
0048 } else
0049 argc = 0;
0050 }
0051
0052 if (argc<2 || argc>3) {
0053 fprintf(stderr, "usage: %s [-V] [-c] [-n] [-v] srcpath [dstpath]\n", progname);
0054 exit(EXIT_FAILURE);
0055 }
0056
0057 #ifdef SIGPIPE
0058 signal(SIGPIPE, sighandle);
0059 #endif
0060 #ifdef SIGHUP
0061 signal(SIGHUP, sighandle);
0062 #endif
0063 signal(SIGINT, sighandle);
0064 signal(SIGTERM, sighandle);
0065
0066 act = "opening environment";
0067 rc = edb_env_create(&env);
0068 if (rc == EDB_SUCCESS) {
0069 rc = edb_env_open(env, argv[1], flags, 0600);
0070 }
0071 if (rc == EDB_SUCCESS) {
0072 act = "copying";
0073 if (argc == 2)
0074 rc = edb_env_copyfd2(env, EDB_STDOUT, cpflags);
0075 else
0076 rc = edb_env_copy2(env, argv[2], cpflags);
0077 }
0078 if (rc)
0079 fprintf(stderr, "%s: %s failed, error %d (%s)\n",
0080 progname, act, rc, edb_strerror(rc));
0081 edb_env_close(env);
0082
0083 return rc ? EXIT_FAILURE : EXIT_SUCCESS;
0084 }