=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sdiff/edit.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/sdiff/edit.c 2006/02/15 06:58:06 1.11 +++ src/usr.bin/sdiff/edit.c 2006/02/20 08:38:18 1.12 @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.11 2006/02/15 06:58:06 otto Exp $ */ +/* $OpenBSD: edit.c,v 1.12 2006/02/20 08:38:18 otto Exp $ */ /* * Written by Raymond Lai . @@ -14,20 +14,11 @@ #include #include +#include "common.h" #include "extern.h" -__dead static void cleanup(const char *); static void edit(const char *); -static char *xmktemp(const char *); -static void -cleanup(const char *filename) -{ - if (unlink(filename)) - err(2, "could not delete: %s", filename); - exit(2); -} - /* * Takes the name of a file and opens it with an editor. */ @@ -72,56 +63,6 @@ cleanup(filename); /* NOTREACHED */ } -} - -/* - * Creates and returns the name of a temporary file. Takes a string - * (or NULL) is written to the temporary file. The returned string - * needs to be freed. - */ -static char * -xmktemp(const char *s) -{ - FILE *file; - int fd; - const char *tmpdir; - char *filename; - - /* If TMPDIR is set, use it; otherwise use /tmp. */ - if (!(tmpdir = getenv("TMPDIR"))) - tmpdir = "/tmp"; - if (asprintf(&filename, "%s/sdiff.XXXXXXXXXX", tmpdir) == -1) - err(2, "xmktemp"); - - /* Create temp file. */ - if ((fd = mkstemp(filename)) == -1) - err(2, "could not create temporary file"); - - /* If we don't write anything to the file, just close. */ - if (s == NULL) { - close(fd); - - return (filename); - } - - /* Open temp file for writing. */ - if ((file = fdopen(fd, "w")) == NULL) { - warn("could not open %s", filename); - cleanup(filename); - /* NOTREACHED */ - } - - /* Write to file. */ - if (fputs(s, file)) { - warn("could not write to %s", filename); - cleanup(filename); - /* NOTREACHED */ - } - - /* Close temp file. */ - fclose(file); - - return (filename); } /*