On 2008-08-15 Sven Joachim <[EMAIL PROTECTED]> wrote: > On 2008-08-15 14:42 +0200, Andreas Metzler wrote:
> > is there actually a reason for using the PID and for limiting the > > non-pid part to [[A-Za-z]? [...] > > - char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; > > + char *alphabet = > > "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-=%#_"; [...] > The later part starting at > /* tricky little algorithm for backward compatibility */ > has to be adjusted as well, since the results are a bit funny: [...] Indeed. I guess it is not worth the effort to use anything except [a-zA-Z0-9] because otherwise 'tricky little algorithm' gets too messy. --------------- --- mktemp-1.5.orig/priv_mktemp.c +++ mktemp-1.5/priv_mktemp.c @@ -80,26 +80,21 @@ { register char *start, *trv; struct stat sbuf; - int pid, rval; - char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + int pid, rval,loopc; + char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; if (doopen && domkdir) { errno = EINVAL; return(0); } - pid = getpid(); for (trv = path; *trv; ++trv) ; --trv; - while (trv >= path && *trv == 'X' && pid != 0) { - *trv-- = (pid % 10) + '0'; - pid /= 10; - } while (trv >= path && *trv == 'X') { char c; - pid = (get_random() & 0xffff) % (26+26); + pid = (get_random() & 0xffff) % (26+26+10); c = alphabet[pid]; *trv-- = c; } @@ -128,7 +123,7 @@ } } - for (;;) { + for (loopc=0;;) { if (doopen) { if ((*doopen = open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) @@ -147,10 +142,15 @@ for (trv = start;;) { if (!*trv) return (0); - if (*trv == 'Z') - *trv++ = 'a'; - else { - if (isdigit((unsigned char)(*trv))) + if (*trv == 'Z') { + if (loopc) + *trv++ = '0'; + else { + *trv = '0'; + loopc++; + } + } else { + if (*trv == '9') *trv = 'a'; else if (*trv == 'z') /* wrap from z to A */ *trv = 'A'; --------------- Afaict this should still work with ebcdic. cu andreas -- `What a good friend you are to him, Dr. Maturin. His other friends are so grateful to you.' `I sew his ears on from time to time, sure' -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]