Check for mkstemp, added a port implementation if it is not
present. Use mkstemp() in various places needing tmp files.

diff --git a/library/port.c b/library/port.c
index def9469..eb93423 100644
--- a/library/port.c
+++ b/library/port.c
@@ -340,6 +340,35 @@
 }
 #endif /* HAVE_LSTAT */
 
+/***********************************************************************
+ *		mkstemp
+ */
+#ifndef HAVE_MKSTEMP
+int mkstemp(char *tmpfn)
+{
+    int tries;
+    char *xstart;
+
+    xstart = tmpfn+strlen(tmpfn)-1;
+    while ((xstart > tmpfn) && (*xstart == 'X'))
+        xstart--;
+    tries = 10;
+    while (tries--) {
+    	char *newfn = mktemp(tmpfn);
+	int fd;
+	if (!newfn) /* something else broke horribly */
+	    return -1;
+	fd = open(newfn,O_CREAT|O_RDWR|O_EXCL,0600);
+	if (fd!=-1)
+	    return fd;
+	newfn = xstart;
+	/* fill up with X and try again ... */
+	while (*newfn) *newfn++ = 'X';
+    }
+    return -1;
+}
+#endif /* HAVE_MKSTEMP */
+
 
 /***********************************************************************
  *		pread