Temporary file handlingRichard Mawhttp://yakking.branchable.com/posts/temporary-file-handling/yakkingikiwiki2014-05-06T20:27:40ZExample code is buggyhttp://yakking.branchable.com/posts/temporary-file-handling/comment_1_0473091fc29ba3b45b84ddbcbd5e9d8a/womble2 [livejournal.com]2014-05-04T21:27:29Z2014-05-04T21:27:29Z
<ul>
<li>mkstemp_with_prefix() and mkdtemp_with_prefix() don't read errno after the failing operation, but after other operations that may reset it.</li>
<li>Running the mkstemp() example with only 1 argument or the mkdtemp() example with only 2 arguments will result in using an uninitialised prefix pointer.</li>
</ul>
<p>Also there are some stylistic oddities:</p>
<ul>
<li>mkstemp_with_prefix() and mkdtemp_with_prefix() have unnecessary while-loops.</li>
<li>asprintf() is used in one place, but not for constructing the full paths.</li>
</ul>
Re: Example code is buggyhttp://yakking.branchable.com/posts/temporary-file-handling/comment_2_a54adc0e5708900c3c65ef695526960f/Richard2014-05-06T12:47:37Z2014-05-06T12:47:37Z
<p>Thanks for the comment. My knowledge of the C standard library had atrophied, since I'd either been reading kernel code or programming in higher level languages, so I'm grateful that you've found some mistakes for me to correct.</p>
<p>While the example programs work as an illustration of how to use the relevant functions, I'd like the examples to be fully correct, so I'll try to have these errors fixed up later this week.</p>
Re: Buggy exampleshttp://yakking.branchable.com/posts/temporary-file-handling/comment_3_328ea7afecfcb5e047502cbd9d4a0860/Richard2014-05-06T20:27:40Z2014-05-06T20:27:39Z
<p>The use of errno was safe, as perror and free don't change errno, but I've made the change, since this is an exception to the norm.</p>
<p>The while loops were a result of following the form of a retry loop, even when one wasn't warranted.</p>
<p>Thanks for the suggestion to use asprintf in more places.</p>