summaryrefslogtreecommitdiff
path: root/bdb/examples_cxx/LockExample.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bdb/examples_cxx/LockExample.cpp')
-rw-r--r--bdb/examples_cxx/LockExample.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/bdb/examples_cxx/LockExample.cpp b/bdb/examples_cxx/LockExample.cpp
index cfab2868098..167900b9476 100644
--- a/bdb/examples_cxx/LockExample.cpp
+++ b/bdb/examples_cxx/LockExample.cpp
@@ -1,27 +1,26 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*
- * $Id: LockExample.cpp,v 11.8 2001/01/04 14:23:30 dda Exp $
+ * $Id: LockExample.cpp,v 11.22 2002/01/11 15:52:15 bostic Exp $
*/
-#include "db_config.h"
-
-#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <errno.h>
-#include <iostream.h>
+#include <iostream>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#endif
#include <db_cxx.h>
-char *progname = "LockExample"; // Program name.
+using std::cin;
+using std::cout;
+using std::cerr;
+
+const char *progname = "LockExample"; // Program name.
//
// An example of a program using DBLock and related classes.
@@ -30,18 +29,20 @@ class LockExample : public DbEnv
{
public:
void run();
+ int error_code() { return (ecode); }
LockExample(const char *home, u_int32_t maxlocks, int do_unlink);
private:
static const char FileName[];
+ int ecode;
// no need for copy and assignment
LockExample(const LockExample &);
void operator = (const LockExample &);
};
-static void usage(); // forward
+static int usage(); // forward
int
main(int argc, char *argv[])
@@ -57,44 +58,51 @@ main(int argc, char *argv[])
for (int argnum = 1; argnum < argc; ++argnum) {
if (strcmp(argv[argnum], "-h") == 0) {
if (++argnum >= argc)
- usage();
+ return (usage());
home = argv[argnum];
}
else if (strcmp(argv[argnum], "-m") == 0) {
if (++argnum >= argc)
- usage();
+ return (usage());
if ((i = atoi(argv[argnum])) <= 0)
- usage();
+ return (usage());
maxlocks = (u_int32_t)i; /* XXX: possible overflow. */
}
else if (strcmp(argv[argnum], "-u") == 0) {
do_unlink = 1;
}
else {
- usage();
+ return (usage());
}
}
try {
+ int ecode;
+
if (do_unlink) {
// Create an environment that immediately
// removes all files.
LockExample tmp(home, maxlocks, do_unlink);
+ if ((ecode = tmp.error_code()) != 0)
+ return (ecode);
}
LockExample app(home, maxlocks, do_unlink);
+ if ((ecode = app.error_code()) != 0)
+ return (ecode);
app.run();
app.close(0);
- return 0;
+ return (EXIT_SUCCESS);
}
catch (DbException &dbe) {
cerr << "LockExample: " << dbe.what() << "\n";
- return 1;
+ return (EXIT_FAILURE);
}
}
LockExample::LockExample(const char *home, u_int32_t maxlocks, int do_unlink)
: DbEnv(0)
+, ecode(0)
{
int ret;
@@ -102,7 +110,7 @@ LockExample::LockExample(const char *home, u_int32_t maxlocks, int do_unlink)
if ((ret = remove(home, DB_FORCE)) != 0) {
cerr << progname << ": DbEnv::remove: "
<< strerror(errno) << "\n";
- exit (1);
+ ecode = EXIT_FAILURE;
}
}
else {
@@ -198,7 +206,7 @@ void LockExample::run()
continue;
}
DbLock lock = locks[lockid];
- ret = lock.put(this);
+ ret = lock_put(&lock);
did_get = 0;
}
@@ -228,9 +236,9 @@ void LockExample::run()
delete locks;
}
-static void
+static int
usage()
{
cerr << "usage: LockExample [-u] [-h home] [-m maxlocks]\n";
- exit(1);
+ return (EXIT_FAILURE);
}