Re: mutt_adv_mktemp() ?
Hi,
* Kyle Wheeler [06-10-04 10:26:52 -0400] wrote:
On Wednesday, October 4 at 07:45 AM, quoth Rocco Rutte:a
The nametemplate should be used. The only effect is that mutt adds the extension on its own because mktemp() and mkstemp() cannot replace a sequence within a string but
only at the end (...which is why we cannot use mkstemp() all over the place).
Two points:
1. For extensions, there is mkstemps(), though it is slightly less portable.
Still someone needs to hack support for it including a configure test.
2. More portably, what's wrong with:
char tmpfile[POSIX_PATH_MAX] = "/tmp/muttXXXXXX";
char tmpfile2[POSIX_PATH_MAX];
char *extension = "foo";
sprintf(tmpfile2, "%s.%s", tmpfile, extension);
fd = mkstemp(tmpfile);
rename(tmpfile, tmpfile2);
Without any reading, I'm not sure if it's a good idea to rename() a file
which is already open. But you still can have races between the test for
the existence of the new file and the actual rename and thus loose data.
bye, Rocco
--
:wq!