$OpenBSD: patch-src_libjasper_base_jas_stream_c,v 1.2 2017/12/14 00:23:28 jca Exp $
Index: src/libjasper/base/jas_stream.c
--- src/libjasper/base/jas_stream.c.orig
+++ src/libjasper/base/jas_stream.c
@@ -513,28 +513,21 @@ jas_stream_t *jas_stream_tmpfile()
 	}
 	obj->fd = -1;
 	obj->flags = 0;
-	obj->pathname[0] = '\0';
 	stream->obj_ = obj;
 
 	/* Choose a file name. */
-	tmpnam(obj->pathname);
+	snprintf(obj->pathname, sizeof obj->pathname, "%stmp.XXXXXXXXXX", P_tmpdir);
 
-	/* Open the underlying file. */
-	if ((obj->fd = open(obj->pathname, O_CREAT | O_EXCL | O_RDWR | O_TRUNC | O_BINARY,
-	  JAS_STREAM_PERMS)) < 0) {
+	if ((obj->fd = mkstemp(obj->pathname)) < 0) {
 		jas_stream_destroy(stream);
 		return 0;
 	}
 
 	/* Unlink the file so that it will disappear if the program
 	terminates abnormally. */
-	/* Under UNIX, one can unlink an open file and continue to do I/O
-	on it.  Not all operating systems support this functionality, however.
-	For example, under Microsoft Windows the unlink operation will fail,
-	since the file is open. */
 	if (unlink(obj->pathname)) {
-		/* We will try unlinking the file again after it is closed. */
-		obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE;
+		jas_stream_destroy(stream);
+		return 0;
 	}
 
 	/* Use full buffering. */
