=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mktemp/mktemp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/usr.bin/mktemp/mktemp.c 1997/01/03 22:49:22 1.2 --- src/usr.bin/mktemp/mktemp.c 1997/06/17 15:34:29 1.3 *************** *** 1,4 **** ! /* $OpenBSD: mktemp.c,v 1.2 1997/01/03 22:49:22 millert Exp $ */ /* * Copyright (c) 1996 Todd C. Miller --- 1,4 ---- ! /* $OpenBSD: mktemp.c,v 1.3 1997/06/17 15:34:29 millert Exp $ */ /* * Copyright (c) 1996 Todd C. Miller *************** *** 31,37 **** */ #ifndef lint ! static char rcsid[] = "$OpenBSD: mktemp.c,v 1.2 1997/01/03 22:49:22 millert Exp $"; #endif /* not lint */ #include --- 31,37 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: mktemp.c,v 1.3 1997/06/17 15:34:29 millert Exp $"; #endif /* not lint */ #include *************** *** 45,51 **** void usage() { ! (void) fprintf(stderr, "Usage: %s [-u] [-q] template\n", __progname); exit(1); } --- 45,52 ---- void usage() { ! (void) fprintf(stderr, "Usage: %s [-d] [-q] [-u] template\n", ! __progname); exit(1); } *************** *** 55,70 **** char **argv; { char *template; ! int ch, uflag = 0, qflag = 0; ! while ((ch = getopt(argc, argv, "uq")) != -1) ! switch(ch) { ! case 'u': ! uflag = 1; break; case 'q': qflag = 1; break; case '?': default: usage(); --- 56,74 ---- char **argv; { char *template; ! int c, uflag = 0, qflag = 0, makedir = 0; ! while ((c = getopt(argc, argv, "dqu")) != -1) ! switch(c) { ! case 'd': ! makedir = 1; break; case 'q': qflag = 1; break; + case 'u': + uflag = 1; + break; case '?': default: usage(); *************** *** 80,94 **** errx(1, "Cannot allocate memory"); } ! if (mkstemp(template) < 0) { ! if (qflag) ! exit(1); ! else ! err(1, "Cannot create temp file %s", template); ! } ! if (uflag) ! (void) unlink(template); (void) puts(template); free(template); --- 84,120 ---- errx(1, "Cannot allocate memory"); } ! if (makedir) { ! for (c = 0; c < 100; c++) { ! if (mktemp(template) == NULL) ! if (qflag) ! exit(1); ! else ! err(1, "Cannot create temp dir %s", ! template); ! if (mkdir(template, 0700) == 0) ! break; ! } ! if (c >= 100) { ! if (qflag) ! exit(1); ! else ! err(1, "Cannot make temp dir %s", template); ! } ! if (uflag) ! (void) rmdir(template); ! } else { ! if (mkstemp(template) < 0) { ! if (qflag) ! exit(1); ! else ! err(1, "Cannot create temp file %s", template); ! } ! ! if (uflag) ! (void) unlink(template); ! } (void) puts(template); free(template);