1 --- mktemp.c.orig Tue Mar 30 22:56:07 2004
2 +++ mktemp.c Tue Mar 30 23:39:22 2004
7 +#include <sys/syslimits.h>
15 - char *start, *trv, *suffp;
16 + char *start, *trv, *suffp, *carryp;
21 + char carrybuf[NAME_MAX];
23 - if (doopen != NULL && domkdir) {
24 + if ((doopen != NULL && domkdir) || slen < 0) {
33 + if (trv < path || NULL != strchr(suffp, '/')) {
41 + /* save first combination of random characters */
42 + memcpy(carrybuf, start, suffp - start);
45 * check the target directory.
48 return (errno == ENOENT);
50 /* If we have a collision, cycle through the space of filenames */
51 - for (trv = start;;) {
52 - if (*trv == '\0' || trv == suffp)
54 + for (trv = start, carryp = carrybuf;;) {
55 + /* have we tried all possible permutations? */
57 + return (0); /* yes - exit with EEXIST */
58 pad = strchr(padchar, *trv);
59 - if (pad == NULL || *++pad == '\0')
60 - *trv++ = padchar[0];
64 + /* this should never happen */
68 + /* increment character */
69 + *trv = (*++pad == '\0') ? padchar[0] : *pad;
70 + /* carry to next position? */
71 + if (*trv == *carryp) {
72 + /* increment position and loop */
76 + /* try with new name */