Checkpoint.
diff --git a/src/cmd/postscript/common/bbox.c b/src/cmd/postscript/common/bbox.c
index 7e1f14a..66a114c 100644
--- a/src/cmd/postscript/common/bbox.c
+++ b/src/cmd/postscript/common/bbox.c
@@ -34,6 +34,7 @@
 
 /*****************************************************************************/
 
+void
 cover(x, y)
 
     double	x, y;
@@ -65,7 +66,9 @@
 }   /* End of cover */
 
 /*****************************************************************************/
+void	resetbbox();
 
+void
 writebbox(fp, keyword, slop)
 
     FILE	*fp;			/* the comment is written here */
@@ -117,7 +120,7 @@
 }   /* End of writebbox */
 
 /*****************************************************************************/
-
+void
 resetbbox(output)
 
     int		output;
@@ -146,7 +149,7 @@
 }   /* End of resetbbox */
 
 /*****************************************************************************/
-
+void
 scale(sx, sy)
 
     double	sx, sy;
@@ -171,7 +174,7 @@
 }   /* End of scale */
 
 /*****************************************************************************/
-
+void
 translate(tx, ty)
 
     double	tx, ty;
@@ -196,7 +199,7 @@
 }   /* End of translate */
 
 /*****************************************************************************/
-
+void
 rotate(angle)
 
     double	angle;
@@ -223,6 +226,7 @@
 
 /*****************************************************************************/
 
+void
 concat(m1)
 
     double	m1[];
diff --git a/src/cmd/postscript/common/common.c b/src/cmd/postscript/common/common.c
index 945ef6a..a58167a 100644
--- a/src/cmd/postscript/common/common.c
+++ b/src/cmd/postscript/common/common.c
@@ -209,14 +209,14 @@
 int
 cat(char *filename) {
 	Biobuf *bfile;
-	Biobuf *Bfile;
+	Biobufhdr *Bfile;
 	int n;
 	static char buf[Bsize];
 
-	if ((bfile = Bopen(unsharp(filename), OREAD)) == 0) {
+	if ((bfile = Bopen(filename, OREAD)) == 0) {
 		return(1);
 	}
-	Bfile = bfile;
+	Bfile = bfile; /* &(bfile->Biobufhdr); */
 	while ((n=Bread(Bfile, buf, Bsize)) > 0) {
 		if (Bwrite(Bstdout, buf, n) != n)
 			break;
@@ -240,9 +240,9 @@
 }
 
 static char *errorstrings[] = {
-	{""},	/* NONE */
-	{"WARNING"},
-	{"FATAL"}
+	"",	/* NONE */
+	"WARNING",
+	"FATAL"
 };
 
 char *programname;
diff --git a/src/cmd/postscript/common/common.h b/src/cmd/postscript/common/common.h
index 62eba08..2432fe1 100644
--- a/src/cmd/postscript/common/common.h
+++ b/src/cmd/postscript/common/common.h
@@ -5,6 +5,8 @@
 #define	RUNEGETGROUP(a)	((a>>8)&0xff)
 #define	RUNEGETCHAR(a)	(a&0xff)
 
+#define tempnam safe_tempnam
+
 typedef	int	BOOLEAN;
 
 #define	TRUE	1
@@ -38,6 +40,6 @@
 void startpage(void);
 void endpage(void);
 int cat(char *);
-int Bgetfield(Biobuf *, int, void *, int);
+int Bgetfield(Biobufhdr *, int, void *, int);
 void *galloc(void *, int, char *);
 void pagelist(char *);
diff --git a/src/cmd/postscript/common/ext.h b/src/cmd/postscript/common/ext.h
index e260cee..c0f7c7a 100644
--- a/src/cmd/postscript/common/ext.h
+++ b/src/cmd/postscript/common/ext.h
@@ -28,8 +28,12 @@
 extern int	optind;
 
 extern void	interrupt();
-//extern char	*tempnam(char*,char*);
+extern void	error();
+extern int	cat();
+extern void	concat();
+
 /* 
+ * extern char	*tempnam(char*,char*);
  * extern char	*malloc();
  * extern char	*calloc();
  * extern char	*strtok();
diff --git a/src/cmd/postscript/common/gen.h b/src/cmd/postscript/common/gen.h
index ba8cbba..dffeb95 100644
--- a/src/cmd/postscript/common/gen.h
+++ b/src/cmd/postscript/common/gen.h
@@ -7,6 +7,10 @@
 
 #define PROGRAMVERSION	"3.3.2"
 
+/* XXX: replace tempnam with something safer, but leaky */
+extern	char*	safe_tempnam(char*, char*);
+#define	tempnam	safe_tempnam
+
 #define NON_FATAL	0
 #define FATAL		1
 #define USER_FATAL	2
diff --git a/src/cmd/postscript/common/getopt.c b/src/cmd/postscript/common/getopt.c
index cf6619f..e348cb2 100644
--- a/src/cmd/postscript/common/getopt.c
+++ b/src/cmd/postscript/common/getopt.c
@@ -15,7 +15,7 @@
 char **argv, *opts;
 {
 	static int sp = 1;
-	register c;
+	register int c;
 	register char *cp;
 
 	if (sp == 1)
diff --git a/src/cmd/postscript/common/misc.c b/src/cmd/postscript/common/misc.c
index 25bd37a..198a935 100644
--- a/src/cmd/postscript/common/misc.c
+++ b/src/cmd/postscript/common/misc.c
@@ -8,6 +8,8 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
 
 #include "gen.h"
 #include "ext.h"
@@ -17,7 +19,9 @@
 int	olist[50];			/* processing range pairs */
 
 /*****************************************************************************/
+extern	int	str_convert();
 
+void
 out_list(str)
 
     char	*str;
@@ -53,7 +57,7 @@
 }   /* End of out_list */
 
 /*****************************************************************************/
-
+int
 in_olist(num)
 
     int		num;
@@ -80,7 +84,7 @@
 }   /* End of in_olist */
 
 /*****************************************************************************/
-
+void
 setencoding(name)
 
     char	*name;
@@ -110,7 +114,7 @@
 }   /* End of setencoding */
 
 /*****************************************************************************/
-
+int
 cat(file)
 
     char	*file;
@@ -145,6 +149,7 @@
 
 /*****************************************************************************/
 
+int
 str_convert(str, err)
 
     char	**str;
@@ -173,6 +178,7 @@
 
 /*****************************************************************************/
 
+void
 error(kind, mesg, a1, a2, a3)
 
     int		kind;
@@ -191,9 +197,9 @@
 	fprintf(stderr, "%s: ", prog_name);
 	fprintf(stderr, mesg, a1, a2, a3);
 	if ( lineno > 0 )
-	    fprintf(stderr, " (line %d)", lineno);
+	    fprintf(stderr, " (line %ld)", lineno);
 	if ( position > 0 )
-	    fprintf(stderr, " (near byte %d)", position);
+	    fprintf(stderr, " (near byte %ld)", position);
 	putc('\n', stderr);
     }	/* End if */
 
diff --git a/src/cmd/postscript/common/path.h b/src/cmd/postscript/common/path.h
index a369213..68f8cbf 100644
--- a/src/cmd/postscript/common/path.h
+++ b/src/cmd/postscript/common/path.h
@@ -4,29 +4,29 @@
  *
  */
 
-#define DPOST		"#9/sys/lib/postscript/prologues/dpost.ps"
-#define POSTBGI		"#9/sys/lib/postscript/prologues/postbgi.ps"
-#define POSTDAISY	"#9/sys/lib/postscript/prologues/postdaisy.ps"
-#define POSTDMD		"#9/sys/lib/postscript/prologues/postdmd.ps"
-#define POSTMD		"#9/sys/lib/postscript/prologues/postmd.ps"
-#define POSTPLOT	"#9/sys/lib/postscript/prologues/postplot.ps"
-#define POSTPRINT	"#9/sys/lib/postscript/prologues/postprint.ps"
-#define POSTNPRINT	"#9/sys/lib/postscript/prologues/postnprint.ps"
-#define POSTTEK		"#9/sys/lib/postscript/prologues/posttek.ps"
-#define POSTGIF		"#9/sys/lib/postscript/prologues/postgif.ps"
+#define DPOST		"#9/postscript/prologues/dpost.ps"
+#define POSTBGI		"#9/postscript/prologues/postbgi.ps"
+#define POSTDAISY	"#9/postscript/prologues/postdaisy.ps"
+#define POSTDMD		"#9/postscript/prologues/postdmd.ps"
+#define POSTMD		"#9/postscript/prologues/postmd.ps"
+#define POSTPLOT	"#9/postscript/prologues/postplot.ps"
+#define POSTPRINT	"#9/postscript/prologues/postprint.ps"
+#define POSTNPRINT	"#9/postscript/prologues/postnprint.ps"
+#define POSTTEK		"#9/postscript/prologues/posttek.ps"
+#define POSTGIF		"#9/postscript/prologues/postgif.ps"
 
-#define BASELINE	"#9/sys/lib/postscript/prologues/baseline.ps"
-#define COLOR		"#9/sys/lib/postscript/prologues/color.ps"
-#define DRAW		"#9/sys/lib/postscript/prologues/draw.ps"
-#define FORMFILE	"#9/sys/lib/postscript/prologues/forms.ps"
-#define SHADEFILE	"#9/sys/lib/postscript/prologues/shade.ps"
-#define KERNING		"#9/sys/lib/postscript/prologues/kerning.ps"
-#define REQUESTFILE	"#9/sys/lib/postscript/prologues/ps.requests"
-#define ROUNDPAGE	"#9/sys/lib/postscript/prologues/roundpage.ps"
+#define BASELINE	"#9/postscript/prologues/baseline.ps"
+#define COLOR		"#9/postscript/prologues/color.ps"
+#define DRAW		"#9/postscript/prologues/draw.ps"
+#define FORMFILE	"#9/postscript/prologues/forms.ps"
+#define SHADEFILE	"#9/postscript/prologues/shade.ps"
+#define KERNING		"#9/postscript/prologues/kerning.ps"
+#define REQUESTFILE	"#9/postscript/prologues/ps.requests"
+#define ROUNDPAGE	"#9/postscript/prologues/roundpage.ps"
 
-#define ENCODINGDIR	"#9/sys/lib/postscript/prologues"
-#define HOSTDIR		"#9/sys/lib/postscript/font"
-#define FONTDIR		"#9/sys/lib/troff/font"
-#define POSTLIBDIR	"#9/sys/lib/postscript/prologues"
-#define TEMPDIR		"/tmp"
+#define ENCODINGDIR	"#9/postscript/prologues"
+#define HOSTDIR		"#9/postscript/font"
+#define FONTDIR		"#9/troff/font"
+#define POSTLIBDIR	"#9/postscript/prologues"
+#define TEMPDIR		"#9/tmp"
 
diff --git a/src/cmd/postscript/common/request.c b/src/cmd/postscript/common/request.c
index d8d7dd1..7884b23 100644
--- a/src/cmd/postscript/common/request.c
+++ b/src/cmd/postscript/common/request.c
@@ -11,8 +11,12 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 #include "gen.h"			/* general purpose definitions */
+#include "ext.h"
 #include "request.h"			/* a few special definitions */
 #include "path.h"			/* for the default request file */
 
@@ -22,6 +26,7 @@
 
 /*****************************************************************************/
 
+void
 saverequest(want)
 
     char	*want;			/* grab code for this stuff */
@@ -55,7 +60,9 @@
 }   /* End of saverequest */
 
 /*****************************************************************************/
+extern	void	dumprequest();
 
+void
 writerequest(page, fp_out)
 
     int		page;			/* write everything for this page */
@@ -80,6 +87,7 @@
 
 /*****************************************************************************/
 
+void
 dumprequest(want, file, fp_out)
 
     char	*want;			/* look for this string */
diff --git a/src/cmd/postscript/common/tempnam.c b/src/cmd/postscript/common/tempnam.c
index 529025e..a759876 100644
--- a/src/cmd/postscript/common/tempnam.c
+++ b/src/cmd/postscript/common/tempnam.c
@@ -1,27 +1,62 @@
 #include <stdio.h>
-#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
-#if defined(V9) || defined(BSD4_2) || defined(plan9)
-char *tempnam(char *dir, char *pfx) {
-	int pid;
-	unsigned int len;
-	char *tnm, *malloc();
-	static int seq = 0;
+#define nil ((void*)0)
 
-	pid = getpid();
-	len = strlen(dir) + strlen(pfx) + 10;
-	if ((tnm = malloc(len)) != NULL) {
-		sprintf(tnm, "%s", dir);
-		if (access(tnm, 7) == -1)
-			return(NULL);
-		do {
-			sprintf(tnm, "%s/%s%d%d", dir, pfx, pid, seq++);
-			errno = 0;
-			if (access(tnm, 7) == -1)
-				if (errno == ENOENT)
-					return(tnm);
-		} while (1);
-	}
-	return(tnm);
+char*
+mkfname(char *tmpdir, char *prefix)
+{
+	int n;
+	char *p, *fname;
+
+	if((p = getenv("TMPDIR")) != nil)
+		goto Mktemp;
+	if((p = tmpdir) != nil)
+		goto Mktemp;
+	p = "/tmp";
+
+ Mktemp:
+	n = strlen(p)+1+strlen(prefix)+1+8+1;
+	if((fname = malloc(n)) == nil)
+		return nil;
+	memset(fname, 0, n);
+	strcat(fname, p);
+	if((n = strlen(p)) > 0 && p[n-1] != '/')
+		strcat(fname, "/");
+	strcat(fname, prefix);
+	strcat(fname, ".XXXXXXXX");
+
+	return fname;
 }
-#endif
+
+extern int mkstemp();
+
+char*
+safe_tempnam(char *tmpdir, char *prefix)
+{
+	int fd;
+	char *fname;
+
+	if((fname = mkfname(tmpdir, prefix)) == nil)
+		return nil;
+
+	if((fd = mkstemp(fname)) < 0){		/* XXX: leak fd, fname */
+		free(fname);
+		return nil;
+	}
+	return fname;
+}
+
+int
+safe_tmpnam(char *fname)
+{
+	char *p;
+
+	if((p = mkfname(nil, "tmpfile")) == nil)
+		return -1;
+	strcpy(fname, p);
+	free(p);
+	return mkstemp(fname);
+}