Index: trunk/src/emx/ChangeLog.LIBC
===================================================================
--- trunk/src/emx/ChangeLog.LIBC	(revision 2028)
+++ trunk/src/emx/ChangeLog.LIBC	(revision 2029)
@@ -6,4 +6,7 @@
         o Fixed potential deadlock the first time a must-complete
           fmutex was entered.
+        o Replaced mktemp and mkstemp with BSD versions. Also adding
+          mkstemps, mkdtemp, arc4random, arc4random_addrandom and
+          arc4random_stir.
 
 2005-06-12: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: trunk/src/emx/include/stdlib.h
===================================================================
--- trunk/src/emx/include/stdlib.h	(revision 2028)
+++ trunk/src/emx/include/stdlib.h	(revision 2029)
@@ -241,8 +241,8 @@
 #endif
 
-/** @todo __uint32_t
-	 arc4random(void); */
-/** @todo void	 arc4random_addrandom(unsigned char *dat, int datlen); */
-/** @todo void	 arc4random_stir(void); */
+__uint32_t
+	 arc4random(void);
+void	 arc4random_addrandom(unsigned char *dat, int datlen);
+void	 arc4random_stir(void);
 char	*getbsize(int *, long *);
 					/* getcap(3) functions */
Index: trunk/src/emx/include/unistd.h
===================================================================
--- trunk/src/emx/include/unistd.h	(revision 2028)
+++ trunk/src/emx/include/unistd.h	(revision 2029)
@@ -501,5 +501,5 @@
 /** @todo int	 iruserok_sa(const void *, int, int, const char *, const char *); */
 int	 issetugid(void);
-/** @todo char	*mkdtemp(char *); */
+char	*mkdtemp(char *);
 int	 mknod(const char *, mode_t, dev_t);
 #ifndef _MKSTEMP_DECLARED
@@ -507,5 +507,5 @@
 #define	_MKSTEMP_DECLARED
 #endif
-/** @todo int	 mkstemps(char *, int); */
+int	 mkstemps(char *, int);
 #ifndef _MKTEMP_DECLARED
 char	*mktemp(char *);
Index: trunk/src/emx/src/lib/bsd/gen/arc4random.c
===================================================================
--- trunk/src/emx/src/lib/bsd/gen/arc4random.c	(revision 2028)
+++ trunk/src/emx/src/lib/bsd/gen/arc4random.c	(revision 2029)
@@ -33,5 +33,9 @@
 #include <fcntl.h>
 #include <unistd.h>
+#ifdef __EMX__
+#include <sys/fmutex.h>
+#else
 #include <pthread.h>
+#endif
 
 #include "libc_private.h"
@@ -44,7 +48,15 @@
 };
 
+#ifdef __EMX__
+static _fmutex	arc4random_mtx = _FMUTEX_INITIALIZER;
+#else
 static pthread_mutex_t	arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
+#endif
 
 #define	RANDOMDEV	"/dev/urandom"
+#ifdef __EMX__
+#define	THREAD_LOCK()   _fmutex_request(&arc4random_mtx, 0)
+#define	THREAD_UNLOCK()	_fmutex_release(&arc4random_mtx)
+#else /* !__EMX__ */
 #define	THREAD_LOCK()						\
 	do {							\
@@ -58,4 +70,5 @@
 			_pthread_mutex_unlock(&arc4random_mtx);	\
 	} while (0)
+#endif
 
 static struct arc4_stream rs;
@@ -114,5 +127,5 @@
 		(void) _read(fd, rdat.rnd, sizeof(rdat.rnd));
 		_close(fd);
-	} 
+	}
 	/* fd < 0?  Ah, what the heck. We'll just take whatever was on the
 	 * stack... */
Index: trunk/src/emx/src/lib/bsd/stdio/mktemp.c
===================================================================
--- trunk/src/emx/src/lib/bsd/stdio/mktemp.c	(revision 2028)
+++ trunk/src/emx/src/lib/bsd/stdio/mktemp.c	(revision 2029)
@@ -58,5 +58,5 @@
 
 int
-mkstemps(path, slen)
+_STD(mkstemps)(path, slen)
 	char *path;
 	int slen;
@@ -68,5 +68,5 @@
 
 int
-mkstemp(path)
+_STD(mkstemp)(path)
 	char *path;
 {
@@ -76,6 +76,7 @@
 }
 
+/* mkstd.awk: NOUNDERSCORE(mkdtemp) */
 char *
-mkdtemp(path)
+_STD(mkdtemp)(path)
 	char *path;
 {
@@ -90,9 +91,11 @@
 }
 
+#ifndef __EMX__
 __warn_references(mktemp,
     "warning: mktemp() possibly used unsafely; consider using mkstemp()");
+#endif
 
 char *
-mktemp(path)
+_STD(mktemp)(path)
 	char *path;
 {
@@ -174,5 +177,5 @@
 			if (*trv == '\0' || trv == suffp)
 				return (0);
-			pad = strchr(padchar, *trv);
+			pad = strchr((const char *)padchar, *trv);
 			if (pad == NULL || *++pad == '\0')
 				*trv++ = padchar[0];
Index: trunk/src/emx/src/lib/bsd/stdio/stdio.smak
===================================================================
--- trunk/src/emx/src/lib/bsd/stdio/stdio.smak	(revision 2029)
+++ trunk/src/emx/src/lib/bsd/stdio/stdio.smak	(revision 2029)
@@ -0,0 +1,1 @@
+libc.TSRC += $(wildcard src/lib/bsd/stdio/*.c)
Index: trunk/src/emx/src/lib/io/mkstemp.c
===================================================================
--- trunk/src/emx/src/lib/io/mkstemp.c	(revision 2028)
+++ 	(revision )
@@ -1,37 +1,0 @@
-/* mkstemp.c (emx+gcc) -- Copyright (c) 1995 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <string.h>
-#include <process.h>
-#include <io.h>
-#include <fcntl.h>
-#include <errno.h>
-
-int _STD(mkstemp) (char *string)
-{
-  int fd, pid, n;
-  char *s;
-
-  pid = getpid ();
-  s = strchr (string, 0);
-  n = 0;
-  while (s != string && s[-1] == 'X')
-    {
-      --s; ++n;
-      *s = (char)(pid % 10) + '0';
-      pid /= 10;
-    }
-  if (n < 2)
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  *s = 'a';
-  for (;;)
-    {
-      fd = open (string, O_RDWR | O_CREAT | O_EXCL, 0600);
-      if (fd >= 0 || errno != EEXIST || *s == 'z')
-        return fd;
-      ++*s;
-    }
-}
Index: trunk/src/emx/src/lib/io/mktemp.c
===================================================================
--- trunk/src/emx/src/lib/io/mktemp.c	(revision 2028)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/* mktemp.c (emx+gcc) -- Copyright (c) 1990-1995 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <string.h>
-#include <process.h>
-#include <io.h>
-#include <errno.h>
-
-char *_STD(mktemp) (char *string)
-{
-  int pid, n, saved_errno;
-  char *s;
-
-  pid = getpid ();
-  s = strchr (string, 0);
-  n = 0;
-  while (s != string && s[-1] == 'X')
-    {
-      --s; ++n;
-      *s = (char)(pid % 10) + '0';
-      pid /= 10;
-    }
-  if (n < 2)
-    return NULL;
-  *s = 'a'; saved_errno = errno;
-  for (;;)
-    {
-      errno = 0;
-      if (access (string, 0) != 0 && errno == ENOENT)
-        {
-          errno = saved_errno;
-          return string;
-        }
-      if (*s == 'z')
-        {
-          errno = saved_errno;
-          return NULL;
-        }
-      ++*s;
-    }
-}
Index: trunk/src/emx/src/lib/libc.def
===================================================================
--- trunk/src/emx/src/lib/libc.def	(revision 2028)
+++ trunk/src/emx/src/lib/libc.def	(revision 2029)
@@ -1712,2 +1712,9 @@
     "___infinity" @1716
     "___nan" @1717
+    ; mktemp + arc4random
+    "_arc4random" @1718
+    "_arc4random_addrandom" @1719
+    "_arc4random_stir" @1720
+    "__mktemp" @1721
+    "__std_mkdtemp" @1722
+    "__std_mkstemps" @1723
