- strcpy((char*)&buf, template);
- if (_mktemp((char*)&buf)) {
- if ((fd=open((char*)&buf, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR))!=-1) {
- strcpy(template, (char*)&buf);
+ /* Fruit fallen from the tree: for people who like
+ microoptimizations, we might not need to copy the whole
+ template on every loop, but only the last several characters.
+ But I didn't feel like testing the boundary cases in Windows's
+ _mktemp. */
+ strncpy(buf, template, PATHNAME_BUFFER_SIZE);
+ buf[PATHNAME_BUFFER_SIZE-1]=0; /* force NULL-termination */
+ if (MKTEMP(buf)) {
+ if ((fd=open(buf, O_CREAT|O_EXCL|O_RDWR, mode))!=-1) {
+ strcpy(template, buf);