]> git.sur5r.net Git - openldap/blobdiff - libraries/liblmdb/mdb_load.c
Happy New Year
[openldap] / libraries / liblmdb / mdb_load.c
index 1f6ce0b7ecae75da54d2f2fa42d7897487a461ec..cf1d42e93bc7d3b8c9271341dc8f270a257c1ba1 100644 (file)
@@ -1,6 +1,6 @@
 /* mdb_load.c - memory-mapped database load tool */
 /*
- * Copyright 2011-2015 Howard Chu, Symas Corp.
+ * Copyright 2011-2018 Howard Chu, Symas Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -248,7 +248,8 @@ badend:
                                        c2 += 2;
                                }
                        } else {
-                               c1++; c2++;
+                               /* copies are redundant when no escapes were used */
+                               *c1++ = *c2++;
                        }
                }
        } else {
@@ -276,7 +277,7 @@ badend:
 
 static void usage(void)
 {
-       fprintf(stderr, "usage: %s dbpath [-V] [-f input] [-n] [-s name] [-N] [-T]\n", prog);
+       fprintf(stderr, "usage: %s [-V] [-f input] [-n] [-s name] [-N] [-T] dbpath\n", prog);
        exit(EXIT_FAILURE);
 }
 
@@ -327,7 +328,7 @@ int main(int argc, char *argv[])
                        putflags = MDB_NOOVERWRITE|MDB_NODUPDATA;
                        break;
                case 'T':
-                       mode |= NOHDR;
+                       mode |= NOHDR | PRINT;
                        break;
                default:
                        usage();
@@ -400,20 +401,22 @@ int main(int argc, char *argv[])
 
                while(1) {
                        rc = readline(&key, &kbuf);
-                       if (rc == EOF)
+                       if (rc)  /* rc == EOF */
                                break;
-                       if (rc)
-                               goto txn_abort;
 
                        rc = readline(&data, &dbuf);
-                       if (rc)
+                       if (rc) {
+                               fprintf(stderr, "%s: line %" Z "d: failed to read key value\n", prog, lineno);
                                goto txn_abort;
-                       
+                       }
+
                        rc = mdb_cursor_put(mc, &key, &data, putflags);
                        if (rc == MDB_KEYEXIST && putflags)
                                continue;
-                       if (rc)
+                       if (rc) {
+                               fprintf(stderr, "mdb_cursor_put failed, error %d %s\n", rc, mdb_strerror(rc));
                                goto txn_abort;
+                       }
                        batch++;
                        if (batch == 100) {
                                rc = mdb_txn_commit(txn);