Index: trunk/src/emx/src/lib/bsd/db/btree/bt_close.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/btree/bt_close.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/btree/bt_close.c	(revision 979)
@@ -71,4 +71,8 @@
 	BTREE *t;
 	int fd;
+#ifdef __EMX__
+	char *tempname;
+	int r;
+#endif /* __EMX__ */
 
 	t = dbp->internal;
@@ -106,7 +110,21 @@
 
 	fd = t->bt_fd;
+#ifdef __EMX__
+	tempname = t->tempname;
+	free(t);
+	free(dbp);
+	r = _close(fd) ? RET_ERROR : RET_SUCCESS;
+	if (tempname != NULL) {
+		int e = errno;
+		(void)unlink (tempname);
+		free (tempname);
+		errno = e;
+	}
+	return r;
+#else /* not __EMX__ */
 	free(t);
 	free(dbp);
 	return (_close(fd) ? RET_ERROR : RET_SUCCESS);
+#endif
 }
 
Index: trunk/src/emx/src/lib/bsd/db/btree/bt_open.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/btree/bt_open.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/btree/bt_open.c	(revision 979)
@@ -213,6 +213,18 @@
 		if ((flags & O_ACCMODE) != O_RDWR)
 			goto einval;
+#ifdef __EMX__
+		{
+		char namestr[] = "btXXXXXX";
+		char absname[MAXPATHLEN];
+		if ((t->bt_fd = mkstemp (namestr)) == -1)
+			goto err;
+		setmode (t->bt_fd, O_BINARY);
+		if (_abspath (absname, namestr, sizeof (absname)) == 0)
+			t->tempname = strdup (absname);
+		}
+#else /* not __EMX__ */
 		if ((t->bt_fd = tmp()) == -1)
 			goto err;
+#endif /* not __EMX__ */
 		F_SET(t, B_INMEM);
 	}
@@ -341,4 +353,10 @@
 		if (t->bt_fd != -1)
 			(void)_close(t->bt_fd);
+#ifdef __EMX__
+		if (t->tempname != NULL) {
+			(void)unlink(t->tempname);
+			free(t->tempname);
+		}
+#endif /* __EMX__ */
 		free(t);
 	}
@@ -389,4 +407,5 @@
 }
 
+#ifndef __EMX__ /* bird */
 static int
 tmp()
@@ -397,7 +416,5 @@
 	char path[MAXPATHLEN];
 
-#ifndef __EMX__ /* bird */
 	if (issetugid() == 0)
-#endif
 		envtmp = getenv("TMPDIR");
 	(void)snprintf(path,
@@ -411,4 +428,5 @@
 	return(fd);
 }
+#endif /*!EMX*/
 
 static int
Index: trunk/src/emx/src/lib/bsd/db/btree/btree.h
===================================================================
--- trunk/src/emx/src/lib/bsd/db/btree/btree.h	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/btree/btree.h	(revision 979)
@@ -380,4 +380,7 @@
 #define	B_DB_TXN	0x10000		/* DB_TXN specified. */
 	u_int32_t flags;
+#ifdef __EMX__
+	char *tempname;			/* Name of temporary file */
+#endif /* __EMX__ */
 } BTREE;
 
Index: trunk/src/emx/src/lib/bsd/db/db/db.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/db/db.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/db/db.c	(revision 979)
@@ -60,5 +60,5 @@
 #define	USE_OPEN_FLAGS							\
 	(O_CREAT | O_EXCL /*| O_EXLOCK*/ | O_NONBLOCK | O_RDONLY |		\
-	 O_RDWR | /*O_SHLOCK |*/ O_TRUNC)
+	 O_RDWR | /*O_SHLOCK |*/ O_TRUNC | O_BINARY)
 #else
 #define	USE_OPEN_FLAGS							\
Index: trunk/src/emx/src/lib/bsd/db/hash/hash.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/hash/hash.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/hash/hash.c	(revision 979)
@@ -444,4 +444,10 @@
 	if (hashp->fp != -1)
 		(void)_close(hashp->fp);
+#ifdef __EMX__
+	if (hashp->tempname != NULL) {
+		(void)unlink (hashp->tempname);
+		free (hashp->tempname);
+		}
+#endif /* __EMX__ */
 
 	free(hashp);
@@ -517,5 +523,5 @@
 		if (wsize != sizeof(HASHHDR)) {
 			errno = EFTYPE;
-			hashp->error = errno;
+			hashp->dbmerrno = errno; /* bird: errno */
 			return (-1);
 		}
@@ -548,5 +554,5 @@
 	hashp = (HTAB *)dbp->internal;
 	if (flag) {
-		hashp->error = errno = EINVAL;
+		hashp->dbmerrno = errno = EINVAL;   /* bird: errno */
 		return (ERROR);
 	}
@@ -565,10 +571,10 @@
 	hashp = (HTAB *)dbp->internal;
 	if (flag && flag != R_NOOVERWRITE) {
-		hashp->error = EINVAL;
+		hashp->dbmerrno = EINVAL;           /* bird: errno */
 		errno = EINVAL;
 		return (ERROR);
 	}
 	if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
-		hashp->error = errno = EPERM;
+		hashp->dbmerrno = errno = EPERM;    /* bird: errno */
 		return (ERROR);
 	}
@@ -587,9 +593,9 @@
 	hashp = (HTAB *)dbp->internal;
 	if (flag && flag != R_CURSOR) {
-		hashp->error = errno = EINVAL;
+		hashp->dbmerrno = errno = EINVAL;   /* bird: errno */
 		return (ERROR);
 	}
 	if ((hashp->flags & O_ACCMODE) == O_RDONLY) {
-		hashp->error = errno = EPERM;
+		hashp->dbmerrno = errno = EPERM;    /* bird: errno */
 		return (ERROR);
 	}
@@ -742,5 +748,5 @@
 	hashp = (HTAB *)dbp->internal;
 	if (flag && flag != R_FIRST && flag != R_NEXT) {
-		hashp->error = errno = EINVAL;
+		hashp->dbmerrno = errno = EINVAL;   /* bird: errno */
 		return (ERROR);
 	}
Index: trunk/src/emx/src/lib/bsd/db/hash/hash.h
===================================================================
--- trunk/src/emx/src/lib/bsd/db/hash/hash.h	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/hash/hash.h	(revision 979)
@@ -73,10 +73,10 @@
 	int		ssize;		/* Segment Size */
 	int		sshift;		/* Segment shift */
-	int		ovfl_point;	/* Where overflow pages are being 
+	int		ovfl_point;	/* Where overflow pages are being
 					 * allocated */
 	int		last_freed;	/* Last overflow page freed */
 	int		max_bucket;	/* ID of Maximum bucket in use */
 	int		high_mask;	/* Mask to modulo into entire table */
-	int		low_mask;	/* Mask to modulo into lower half of 
+	int		low_mask;	/* Mask to modulo into lower half of
 					 * table */
 	int		ffactor;	/* Fill factor */
@@ -84,8 +84,8 @@
 	int		hdrpages;	/* Size of table header */
 	int		h_charkey;	/* value of hash(CHARKEY) */
-#define NCACHED	32			/* number of bit maps and spare 
+#define NCACHED	32			/* number of bit maps and spare
 					 * points */
 	int		spares[NCACHED];/* spare pages for overflow */
-	u_int16_t	bitmaps[NCACHED];	/* address of overflow page 
+	u_int16_t	bitmaps[NCACHED];	/* address of overflow page
 						 * bitmaps */
 } HASHHDR;
@@ -94,5 +94,5 @@
 	HASHHDR 	hdr;		/* Header */
 	int		nsegs;		/* Number of allocated segments */
-	int		exsegs;		/* Number of extra allocated 
+	int		exsegs;		/* Number of extra allocated
 					 * segments */
 	u_int32_t			/* Hash function */
@@ -105,17 +105,21 @@
 	int		cbucket;	/* Current bucket */
 	int		cndx;		/* Index of next item on cpage */
-	int		error;		/* Error Number -- for DBM 
-					 * compatibility */
-	int		new_file;	/* Indicates if fd is backing store 
+        /* bird: this used to be errno but that crashes with the errno define in errno.h and stdlib.h. */
+	int		dbmerrno;	/* Error Number -- for DBM
+					 * compatability */
+	int		new_file;	/* Indicates if fd is backing store
 					 * or no */
-	int		save_file;	/* Indicates whether we need to flush 
+	int		save_file;	/* Indicates whether we need to flush
 					 * file at
 					 * exit */
 	u_int32_t	*mapp[NCACHED];	/* Pointers to page maps */
 	int		nmaps;		/* Initial number of bitmaps */
-	int		nbufs;		/* Number of buffers left to 
+	int		nbufs;		/* Number of buffers left to
 					 * allocate */
 	BUFHEAD 	bufhead;	/* Header of buffer lru list */
 	SEGMENT 	*dir;		/* Hash Bucket directory */
+#ifdef __EMX__
+	char		*tempname;	/* Name of temporary file */
+#endif /* __EMX__ */
 } HTAB;
 
Index: trunk/src/emx/src/lib/bsd/db/hash/hash_page.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/hash/hash_page.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/hash/hash_page.c	(revision 979)
@@ -69,4 +69,7 @@
 #ifdef DEBUG
 #include <assert.h>
+#endif
+#ifdef __EMX__
+#include <io.h>
 #endif
 #include "un-namespace.h"
@@ -868,5 +871,9 @@
 {
 	sigset_t set, oset;
+#ifdef __EMX__
+	char namestr[] = "hsXXXXXX";
+#else /* not __EMX__ */
 	static char namestr[] = "_hashXXXXXX";
+#endif /* not __EMX__ */
 
 	/* Block signals; make sure file goes away at process exit. */
@@ -874,5 +881,12 @@
 	(void)_sigprocmask(SIG_BLOCK, &set, &oset);
 	if ((hashp->fp = mkstemp(namestr)) != -1) {
+#ifdef __EMX__
+		char absname[_MAX_PATH];
+		setmode (hashp->fp, O_BINARY);
+		if (_abspath (absname, namestr, sizeof (absname)) == 0)
+			hashp->tempname = strdup (absname);
+#else /* not __EMX__ */
 		(void)unlink(namestr);
+#endif /* not __EMX__ */
 		(void)_fcntl(hashp->fp, F_SETFD, 1);
 	}
Index: trunk/src/emx/src/lib/bsd/db/hash/ndbm.c
===================================================================
--- trunk/src/emx/src/lib/bsd/db/hash/ndbm.c	(revision 978)
+++ trunk/src/emx/src/lib/bsd/db/hash/ndbm.c	(revision 979)
@@ -211,5 +211,5 @@
 
 	hp = (HTAB *)db->internal;
-	return (hp->error);
+	return (hp->dbmerrno);          /* bird: errno */
 }
 
@@ -221,5 +221,5 @@
 
 	hp = (HTAB *)db->internal;
-	hp->error = 0;
+	hp->dbmerrno = 0;               /* bird: errno */
 	return (0);
 }
