=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sdiff/common.c,v retrieving revision 1.3 retrieving revision 1.4 diff -c -r1.3 -r1.4 *** src/usr.bin/sdiff/common.c 2006/05/10 14:32:51 1.3 --- src/usr.bin/sdiff/common.c 2006/05/25 03:20:32 1.4 *************** *** 1,4 **** ! /* $OpenBSD: common.c,v 1.3 2006/05/10 14:32:51 ray Exp $ */ /* * Written by Raymond Lai . --- 1,4 ---- ! /* $OpenBSD: common.c,v 1.4 2006/05/25 03:20:32 ray Exp $ */ /* * Written by Raymond Lai . *************** *** 6,13 **** */ #include - #include - #include #include #include --- 6,11 ---- *************** *** 19,70 **** if (unlink(filename)) err(2, "could not delete: %s", filename); exit(2); - } - - /* - * 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. - */ - char * - xmktemp(const char *s) - { - FILE *file; - int fd; - const char *tmpdir; - char *filename; - - /* If TMPDIR is set, use it; otherwise use _PATH_TMP. */ - if (!(tmpdir = getenv("TMPDIR"))) - tmpdir = _PATH_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); - } - - /* Write to file. */ - if (fputs(s, file)) { - warn("could not write to %s", filename); - cleanup(filename); - } - - /* Close temp file. */ - fclose(file); - - return (filename); } --- 17,20 ----