=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mktemp/mktemp.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/mktemp/mktemp.c 2002/02/16 21:27:49 1.8 --- src/usr.bin/mktemp/mktemp.c 2003/04/07 19:25:43 1.9 *************** *** 1,4 **** ! /* $OpenBSD: mktemp.c,v 1.8 2002/02/16 21:27:49 millert Exp $ */ /* * Copyright (c) 1996, 1997, 2001 Todd C. Miller --- 1,4 ---- ! /* $OpenBSD: mktemp.c,v 1.9 2003/04/07 19:25:43 millert Exp $ */ /* * Copyright (c) 1996, 1997, 2001 Todd C. Miller *************** *** 28,34 **** */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: mktemp.c,v 1.8 2002/02/16 21:27:49 millert Exp $"; #endif /* not lint */ #include --- 28,34 ---- */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: mktemp.c,v 1.9 2003/04/07 19:25:43 millert Exp $"; #endif /* not lint */ #include *************** *** 47,53 **** { int ch, fd, uflag = 0, quiet = 0, tflag = 0, makedir = 0; char *cp, *template, *tempfile, *prefix = _PATH_TMP; ! size_t plen; while ((ch = getopt(argc, argv, "dp:qtu")) != -1) switch(ch) { --- 47,53 ---- { int ch, fd, uflag = 0, quiet = 0, tflag = 0, makedir = 0; char *cp, *template, *tempfile, *prefix = _PATH_TMP; ! int plen; while ((ch = getopt(argc, argv, "dp:qtu")) != -1) switch(ch) { *************** *** 87,93 **** if (tflag) { if (strchr(template, '/')) { if (!quiet) ! warnx("template must not contain directory separators in -t mode"); exit(1); } --- 87,94 ---- if (tflag) { if (strchr(template, '/')) { if (!quiet) ! warnx("template must not contain directory " ! "separators in -t mode"); exit(1); } *************** *** 98,118 **** while (plen != 0 && prefix[plen - 1] == '/') plen--; ! tempfile = (char *)malloc(plen + 1 + strlen(template) + 1); ! if (tempfile == NULL) { ! if (!quiet) ! warnx("cannot allocate memory"); ! exit(1); ! } ! (void)memcpy(tempfile, prefix, plen); ! tempfile[plen] = '/'; ! (void)strcpy(tempfile + plen + 1, template); /* SAFE */ ! } else { ! if ((tempfile = strdup(template)) == NULL) { ! if (!quiet) ! warnx("cannot allocate memory"); ! exit(1); ! } } if (makedir) { --- 99,112 ---- while (plen != 0 && prefix[plen - 1] == '/') plen--; ! tempfile = NULL; ! asprintf(&tempfile, "%.*s/%s", plen, prefix, template); ! } else ! tempfile = strdup(template); ! if (tempfile == NULL) { ! if (!quiet) ! warnx("cannot allocate memory"); ! exit(1); } if (makedir) {