B20.1: bug in mkstemp
John Poplett
jpoplett@mindspring.com
Sat Sep 11 12:24:00 GMT 1999
mkstemp fails with an access errror when an attempt is made to
create more than one file using the same mkstemp template. This problem was
reported previously by Rob Mayoff.
ÃÂ
In Rob's original report, he gives the following program that
demonstrates the problem:
ÃÂ
In this program, the second call to mkstemp will
fail:
ÃÂ
#include <stdio.h> #include
<sys/param.h>
ÃÂ
main() { ÃÂ char
path[MAXPATHLEN]; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ int fd,
rc;
ÃÂ
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ sprintf(path,
"/tmp/test.XXXXXX"); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ fd
= mkstemp(path); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if (fd < 0) {
perror("mkstemp 1"); exit(1);
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ rc =
unlink(path); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if (rc < 0) {
perror("unlink"); exit(1);
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ sprintf(path,
"/tmp/test.XXXXXX"); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ fd
= mkstemp(path); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if (fd < 0) {
perror("mkstemp 2"); exit(1);
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ rc =
unlink(path); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if (rc < 0) {
perror("unlink"); exit(1); }
ÃÂ
ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
exit(0); }
ÃÂ
The fix should be simply to treat EACCES just like EEXIST in
mkstemp.
ÃÂ
I have applied a patch to the runtime source file, mktemp.c,
as Rob suggests and
verified the fix. I include the patch as an
attachment.
ÃÂ
John
ÃÂ
John Poplett
jpoplett@mindspring.com
mktemp.c
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
More information about the Cygwin
mailing list