/* ***************************************************************************** * * $RCSfile: xml_mktemp.c,v $ * $Date: 1998/06/23 14:43:44 $ * $Source: /home/richard/Xml/RCS/xml_mktemp.c,v $ * $Revision: 1.1 $ * $Author: richard $ * ***************************************************************************** * * Copyright 1998, Brown University and Richard Goerwitz * ***************************************************************************** * * Simple utility for creating temporary files. Basically this is just * an interface to mktemp(3). A typical invocation might look like: * * mktemp progname.XXXXXX * ***************************************************************************** */ #include "general.h" #include #include #ifdef STDC_HEADERS # include #else # ifdef HAVE_VARARGS_H # include # else # error "Find and include your stdarg/vararg header file!" # endif #endif static void die_nice (int, char *, ...); int main (int argc, char **argv) { int fd; char *p, *p2, *progname; p2 = NULL; for (p = argv[0]; *p != '\0'; p++) if (*p == '/') p2 = p + 1; if (p2 == NULL || *p2 == '\0') p2 = argv[0]; progname = p2; if (argc != 2) die_nice (1, "Usage: %s template\n", progname); p = strdup (argv[1]); if (mktemp (p) == NULL || *p == 0) die_nice (2, "%s: Can't create template from %s\n", argv[1]); if ((fd = open (p, O_CREAT | O_EXCL | O_RDWR, 0600)) < 0) die_nice (3, "%s: Can't create temp file, %s\n", progname, p); puts (p); close (fd); exit(0); } static void die_nice (int i, char *template, ...) { va_list ap; #ifdef STDC_HEADERS va_start (ap, template); #else va_start (ap); #endif vfprintf (stderr, template, ap); va_end (ap); exit (i); }