aboutsummaryrefslogtreecommitdiff
path: root/db2
diff options
context:
space:
mode:
Diffstat (limited to 'db2')
-rw-r--r--db2/README3
-rw-r--r--db2/btree/bt_rec.c4
-rw-r--r--db2/clib/getlong.c3
-rw-r--r--db2/db185/db185.c67
-rw-r--r--db2/db185/db185_int.h1
-rw-r--r--db2/db_int.h6
-rw-r--r--db2/dbm/dbm.c12
-rw-r--r--db2/lock/lock_deadlock.c6
-rw-r--r--db2/log/log_archive.c2
9 files changed, 59 insertions, 45 deletions
diff --git a/db2/README b/db2/README
new file mode 100644
index 0000000..2dc1d1b
--- /dev/null
+++ b/db2/README
@@ -0,0 +1,3 @@
+The LICENSE file, mentioned in the beginning of the source files, can
+be found together with all the other relevant license texts in the
+manual and the INSTALL file in the toplevel directory.
diff --git a/db2/btree/bt_rec.c b/db2/btree/bt_rec.c
index bf48e01..07a3d93 100644
--- a/db2/btree/bt_rec.c
+++ b/db2/btree/bt_rec.c
@@ -301,7 +301,7 @@ __bam_split_recover(logp, dbtp, lsnp, redo, info)
if ((_lp = (PAGE *)malloc(file_dbp->pgsize)) == NULL)
goto nomem;
if ((_rp = (PAGE *)malloc(file_dbp->pgsize)) == NULL) {
-nomem: errno = ENOMEM;
+nomem: __set_errno(ENOMEM);
__db_err(file_dbp->dbenv, "%s", strerror(errno));
goto out;
}
@@ -668,7 +668,7 @@ __bam_cadjust_recover(logp, dbtp, lsnp, redo, info)
REC_INTRO(__bam_cadjust_read);
if ((ret = memp_fget(mpf, &argp->pgno, 0, &pagep)) != 0) {
- errno = __db_pgerr(file_dbp, argp->pgno);
+ __set_errno(__db_pgerr(file_dbp, argp->pgno));
pagep = NULL;
goto out;
}
diff --git a/db2/clib/getlong.c b/db2/clib/getlong.c
index d79c684..0cc8567 100644
--- a/db2/clib/getlong.c
+++ b/db2/clib/getlong.c
@@ -18,6 +18,7 @@ static const char sccsid[] = "@(#)getlong.c 10.2 (Sleepycat) 5/1/97";
#endif
#include "db.h"
+#include "db_int.h"
#include "clib_ext.h"
/*
@@ -34,7 +35,7 @@ get_long(p, min, max, storep)
long val;
char *end;
- errno = 0;
+ __set_errno(0);
val = strtol(p, &end, 10);
if ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE)
err(1, "%s", p);
diff --git a/db2/db185/db185.c b/db2/db185/db185.c
index 8e53a1b..bf5e37e 100644
--- a/db2/db185/db185.c
+++ b/db2/db185/db185.c
@@ -38,7 +38,7 @@ static int db185_seq __P((const DB185 *, DBT185 *, DBT185 *, u_int));
static int db185_sync __P((const DB185 *, u_int));
DB185 *
-dbopen(file, oflags, mode, type, openinfo)
+__dbopen(file, oflags, mode, type, openinfo)
const char *file;
int oflags, mode;
DBTYPE type;
@@ -181,18 +181,19 @@ dbopen(file, oflags, mode, type, openinfo)
* Store the returned pointer to the real DB 2.0 structure in the
* internal pointer. Ugly, but we're not going for pretty, here.
*/
- if ((errno = db_open(file,
- type, __db_oflags(oflags), mode, NULL, dbinfop, &dbp)) != 0) {
+ if ((__set_errno(db_open(file,
+ type, __db_oflags(oflags), mode, NULL, dbinfop, &dbp))) != 0) {
free(db185p);
return (NULL);
}
/* Create the cursor used for sequential ops. */
- if ((errno = dbp->cursor(dbp, NULL, &((DB185 *)db185p)->dbc)) != 0) {
+ if ((__set_errno(dbp->cursor(dbp, NULL, &((DB185 *)db185p)->dbc)))
+ != 0) {
s_errno = errno;
(void)dbp->close(dbp, 0);
free(db185p);
- errno = s_errno;
+ __set_errno(s_errno);
return (NULL);
}
@@ -200,9 +201,10 @@ dbopen(file, oflags, mode, type, openinfo)
return (db185p);
einval: free(db185p);
- errno = EINVAL;
+ __set_errno(EINVAL);
return (NULL);
}
+weak_alias (__dbopen, dbopen)
static int
db185_close(db185p)
@@ -212,7 +214,7 @@ db185_close(db185p)
dbp = (DB *)db185p->internal;
- errno = dbp->close(dbp, 0);
+ __set_errno(dbp->close(dbp, 0));
free(db185p);
@@ -237,9 +239,9 @@ db185_del(db185p, key185, flags)
if (flags & ~R_CURSOR)
goto einval;
if (flags & R_CURSOR)
- errno = db185p->dbc->c_del(db185p->dbc, 0);
+ __set_errno(db185p->dbc->c_del(db185p->dbc, 0));
else
- errno = dbp->del(dbp, NULL, &key, 0);
+ __set_errno(dbp->del(dbp, NULL, &key, 0));
switch (errno) {
case 0:
@@ -249,7 +251,7 @@ db185_del(db185p, key185, flags)
}
return (-1);
-einval: errno = EINVAL;
+einval: __set_errno(EINVAL);
return (-1);
}
@@ -262,7 +264,7 @@ db185_fd(db185p)
dbp = (DB *)db185p->internal;
- return ((errno = dbp->fd(dbp, &fd)) == 0 ? fd : -1);
+ return ((__set_errno(dbp->fd(dbp, &fd))) == 0 ? fd : -1);
}
static int
@@ -287,7 +289,7 @@ db185_get(db185p, key185, data185, flags)
if (flags)
goto einval;
- switch (errno = dbp->get(dbp, NULL, &key, &data, 0)) {
+ switch (__set_errno(dbp->get(dbp, NULL, &key, &data, 0))) {
case 0:
data185->data = data.data;
data185->size = data.size;
@@ -297,7 +299,7 @@ db185_get(db185p, key185, data185, flags)
}
return (-1);
-einval: errno = EINVAL;
+einval: __set_errno(EINVAL);
return (-1);
}
@@ -324,46 +326,46 @@ db185_put(db185p, key185, data185, flags)
switch (flags) {
case 0:
- errno = dbp->put(dbp, NULL, &key, &data, 0);
+ __set_errno(dbp->put(dbp, NULL, &key, &data, 0));
break;
case R_CURSOR:
- errno =
- db185p->dbc->c_put(db185p->dbc, &key, &data, DB_CURRENT);
+ __set_errno(
+ db185p->dbc->c_put(db185p->dbc, &key, &data, DB_CURRENT));
break;
case R_IAFTER:
case R_IBEFORE:
if (dbp->type != DB_RECNO)
goto einval;
- if ((errno = dbp->cursor(dbp, NULL, &dbcp_put)) != 0)
+ if ((__set_errno(dbp->cursor(dbp, NULL, &dbcp_put))) != 0)
return (-1);
- if ((errno =
- dbcp_put->c_get(dbcp_put, &key, &data, DB_SET)) != 0) {
+ if ((__set_errno(
+ dbcp_put->c_get(dbcp_put, &key, &data, DB_SET))) != 0) {
s_errno = errno;
(void)dbcp_put->c_close(dbcp_put);
- errno = s_errno;
+ __set_errno(s_errno);
return (-1);
}
memset(&data, 0, sizeof(data));
data.data = data185->data;
data.size = data185->size;
- errno = dbcp_put->c_put(dbcp_put,
- &key, &data, flags == R_IAFTER ? DB_AFTER : DB_BEFORE);
+ __set_errno(dbcp_put->c_put(dbcp_put,
+ &key, &data, flags == R_IAFTER ? DB_AFTER : DB_BEFORE));
s_errno = errno;
(void)dbcp_put->c_close(dbcp_put);
- errno = s_errno;
+ __set_errno(s_errno);
break;
case R_NOOVERWRITE:
- errno = dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE);
+ __set_errno(dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE));
break;
case R_SETCURSOR:
if (dbp->type != DB_BTREE && dbp->type != DB_RECNO)
goto einval;
- if ((errno = dbp->put(dbp, NULL, &key, &data, 0)) != 0)
+ if ((__set_errno(dbp->put(dbp, NULL, &key, &data, 0))) != 0)
break;
- errno =
- db185p->dbc->c_get(db185p->dbc, &key, &data, DB_SET_RANGE);
+ __set_errno(db185p->dbc->c_get(db185p->dbc,
+ &key, &data, DB_SET_RANGE));
break;
default:
goto einval;
@@ -379,7 +381,7 @@ db185_put(db185p, key185, data185, flags)
}
return (-1);
-einval: errno = EINVAL;
+einval: __set_errno(EINVAL);
return (-1);
}
@@ -424,7 +426,8 @@ db185_seq(db185p, key185, data185, flags)
default:
goto einval;
}
- switch (errno = db185p->dbc->c_get(db185p->dbc, &key, &data, flags)) {
+ switch (__set_errno(db185p->dbc->c_get(db185p->dbc,
+ &key, &data, flags))) {
case 0:
key185->data = key.data;
key185->size = key.size;
@@ -436,7 +439,7 @@ db185_seq(db185p, key185, data185, flags)
}
return (-1);
-einval: errno = EINVAL;
+einval: __set_errno(EINVAL);
return (-1);
}
@@ -464,8 +467,8 @@ db185_sync(db185p, flags)
goto einval;
}
- return ((errno = dbp->sync(dbp, 0)) == 0 ? 0 : -1);
+ return ((__set_errno(dbp->sync(dbp, 0))) == 0 ? 0 : -1);
-einval: errno = EINVAL;
+einval: __set_errno(EINVAL);
return (-1);
}
diff --git a/db2/db185/db185_int.h b/db2/db185/db185_int.h
index 656dfdd..f3e24b9 100644
--- a/db2/db185/db185_int.h
+++ b/db2/db185/db185_int.h
@@ -130,6 +130,7 @@ typedef struct {
#if defined(__cplusplus)
extern "C" {
#endif
+DB185 *__dbopen __P((const char *, int, int, DBTYPE, const void *));
DB185 *dbopen __P((const char *, int, int, DBTYPE, const void *));
#if defined(__cplusplus)
};
diff --git a/db2/db_int.h b/db2/db_int.h
index 23fb106..a088c69 100644
--- a/db2/db_int.h
+++ b/db2/db_int.h
@@ -25,6 +25,12 @@
#define DB_MINCACHE 10 /* Minimum cached pages */
+/* Handle `errno' in the presence of multi-threading correctly. On some
+ systems we need a special macro to do this right. */
+#ifndef __set_errno
+# define __set_errno(val) (errno) = (val)
+#endif
+
/*
* Aligning items to particular sizes or in pages or memory. ALIGNP is a
* separate macro, as we've had to cast the pointer to different integral
diff --git a/db2/dbm/dbm.c b/db2/dbm/dbm.c
index fb21ade..1fa92ce 100644
--- a/db2/dbm/dbm.c
+++ b/db2/dbm/dbm.c
@@ -199,8 +199,8 @@ dbm_open(file, oflags, mode)
dbinfo.h_nelem = 1;
(void)snprintf(path, sizeof(path), "%s%s", file, DBM_SUFFIX);
- if ((errno = db_open(path,
- DB_HASH, __db_oflags(oflags), mode, NULL, &dbinfo, &dbp)) != 0)
+ if ((__set_errno(db_open(path,
+ DB_HASH, __db_oflags(oflags), mode, NULL, &dbinfo, &dbp))) != 0)
return (NULL);
return ((DBM *)dbp);
}
@@ -261,7 +261,7 @@ dbm_firstkey(db)
DBC *cp;
if ((cp = TAILQ_FIRST(&db->curs_queue)) == NULL)
- if ((errno = db->cursor(db, NULL, &cp)) != 0) {
+ if ((__set_errno(db->cursor(db, NULL, &cp))) != 0) {
memset(&key, 0, sizeof(key));
return (key);
}
@@ -294,7 +294,7 @@ dbm_nextkey(db)
int status;
if ((cp = TAILQ_FIRST(&db->curs_queue)) == NULL)
- if ((errno = db->cursor(db, NULL, &cp)) != 0) {
+ if ((__set_errno(db->cursor(db, NULL, &cp))) != 0) {
memset(&key, 0, sizeof(key));
return (key);
}
@@ -330,9 +330,9 @@ dbm_delete(db, key)
_key.size = key.dsize;
ret = (((DB *)db)->del)((DB *)db, NULL, &_key, 0);
if (ret < 0)
- errno = ENOENT;
+ __set_errno(ENOENT);
else if (ret > 0) {
- errno = ret;
+ __set_errno(ret);
ret = -1;
}
return (ret);
diff --git a/db2/lock/lock_deadlock.c b/db2/lock/lock_deadlock.c
index 54a73af..f753958 100644
--- a/db2/lock/lock_deadlock.c
+++ b/db2/lock/lock_deadlock.c
@@ -300,8 +300,8 @@ retry: count = lt->region->nlockers;
for (lp = SH_TAILQ_FIRST(&op->holders, __db_lock);
lp != NULL;
lp = SH_TAILQ_NEXT(lp, links, __db_lock)) {
- if ((errno = __lock_getobj(lt, lp->holder,
- NULL, DB_LOCK_LOCKER, &lockerp)) != 0) {
+ if ((__set_errno(__lock_getobj(lt, lp->holder,
+ NULL, DB_LOCK_LOCKER, &lockerp))) != 0) {
__db_err(dbenv,
"warning unable to find object");
continue;
@@ -472,7 +472,7 @@ __dd_debug(dbenv, idmap, bitmap, nlockers)
* Alloc space to print 10 bytes per item waited on.
*/
if ((msgbuf = (char *)malloc((nlockers + 1) * 10 + 64)) == NULL) {
- errno = ENOMEM;
+ __set_errno(ENOMEM);
__db_err(dbenv, "%s", strerror(errno));
return;
}
diff --git a/db2/log/log_archive.c b/db2/log/log_archive.c
index d70d4c6..0d6c3f2 100644
--- a/db2/log/log_archive.c
+++ b/db2/log/log_archive.c
@@ -68,7 +68,7 @@ log_archive(logp, listp, flags, db_malloc)
* but that's just not possible.
*/
if (LF_ISSET(DB_ARCH_ABS)) {
- errno = 0;
+ __set_errno(0);
if ((pref = getcwd(buf, sizeof(buf))) == NULL)
return (errno == 0 ? ENOMEM : errno);
} else