GNOME Bugzilla – Bug 118563
Add g_mkdtemp in the spirit of g_mkstemp
Last modified: 2011-08-14 18:18:04 UTC
Add a g_mkdtemp in the spirit of g_mkstemp for the benefit of non-glibc based platforms. Make it a thin wrapper on mkdtemp for platforms that has it. Patch attached below. Should be checked against the glibc implementation, doesn't have it as of this writing.
Created attachment 18714 [details] [review] Patch to add a g_mkdtemp call to glib
If we add this we should probably also add a more glib-style function parallel to g_file_open_tmp, e.g void g_dir_create_tmp (const gchar *tmpl, gchar **name_used, GError **error);
In terms of implementation, I don't think duplicating a big chunk of random name generation code between mkdtemp and mkstemp makes sense, so that should be unified in some way. (glibc makes all of mkstemp/mkdtemp/mktemp simply wrappers that call __gen_tempname (template, __GT_DIR)), etc.)
*** Bug 150091 has been marked as a duplicate of this bug. ***
*** Bug 343909 has been marked as a duplicate of this bug. ***
Is this still valid?
*** Bug 524831 has been marked as a duplicate of this bug. ***
The last dupe has an alternative patch
looks like the main difference is that my patch allows the XXXXXX to be anywhere in the string (just like g_mkstemp and friends) whereas the patch in this bug report uses mkdtemp() if it is available (which breaks the expected behavior of allowing the XXXXXX to be anywhere in the string but the end).
Created attachment 158959 [details] [review] updated g_mkdtemp() patch with Owen's suggestion This patch, like my previous patch, is consistent with g_mkstemp(), allowing the XXXXXX to be anywhere in the template string. I've also taken Owen's suggestion and split out the code that fills in the XXXXXX with random chars and updated all of the functions to use that (including the new g_mkdtemp() function).
Created attachment 158963 [details] [review] make g_mkstemp, g_mkdtemp, and g_mkstemp_full all simple wrappers around an internal function that does everything this patch makes g_mkstemp, g_mkdtemp, and g_mkstemp_full all simple wrappers around an internal g_mktemp function that does everything, not just the XXXXXX logic.
Created attachment 158965 [details] [review] make g_mkstemp, g_mkdtemp, and g_mkstemp_full all simple wrappers around an internal function that does everything Oops, this fixes the second g_mkstemp implementation at the end of the file
*** Bug 615898 has been marked as a duplicate of this bug. ***
See also attachment 158852 [details] [review] from bug 615898, which uses a more flexible internal function and thus commonizes also the legacy (non-UTF8) g_mkstemp implementation.
... and includes testcases. :-)
Created attachment 159093 [details] [review] patch to implement g_dir_make_tmp Addendum patch to attachment 158852 [details] [review], implements a variant with GError support.
ping for patch of comment 16?
Evolution-EWS needs a mkdtemp too...
I've committed Paolo's patches. Thanks, and sorry for the long wait.