/* This is a replacement function for mkdtemp in case the platform we're building on (like mine!) doesn't have it. */ #include #include #include #include #include #include #include #include "types.h" #include "cipher.h" char *mkdtemp(char *template) { int attempts,idx,count=0; byte *ch; idx=strlen(template); if(idx==0) { errno=EINVAL; return NULL; } ch=&template[idx-1]; /* Walk backwards to count all the Xes */ while(*ch=='X' && count1) { sprintf(marker,"%02X",randombits[idx++]); marker+=2; remaining-=2; } /* Any leftover Xes? get_random_bits rounds up to full bytes, so this is safe. */ if(remaining>0) sprintf(marker,"%X",randombits[idx]&0xF); m_free(randombits); if(mkdir(template,0700)==0) break; } if(attempts==4) return NULL; /* keeps the errno from mkdir, whatever it is */ return template; }