summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2020-10-01 10:37:47 -0400
committerRebecca Turner <rbt@sent.as>2020-10-01 10:37:47 -0400
commita5b76690b1c351cee5aede6e1a476bd955d1b00c (patch)
treeb3f33c67f8d4d227fa63577bf4c1ce4adb609fd0
parent1ea9158c24ab0c775c23403e853cc27bb0155d27 (diff)
downloadlibglnx-a5b76690b1c351cee5aede6e1a476bd955d1b00c.tar.gz
glnx-fdio: use $TMPDIR if set
As suggested by Colin Walters.
-rw-r--r--glnx-fdio.c39
1 files changed, 6 insertions, 33 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index 9cf595e..422bc2d 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -303,8 +303,8 @@ glnx_open_anonymous_tmpfile_full (int flags,
}
/* A variant of `glnx_open_tmpfile_linkable_at()` which doesn't support linking.
- * Useful for true temporary storage. The fd will be allocated in `/var/tmp`
- * (or `$TMPDIR` if `/var/tmp` doesn't exist) to ensure maximum storage space.
+ * Useful for true temporary storage. The fd will be allocated in `$TMPDIR` if
+ * set or `/var/tmp` otherwise.
*
* If you need the file on a specific filesystem use glnx_open_anonymous_tmpfile_full()
* which lets you pass a directory.
@@ -314,37 +314,10 @@ glnx_open_anonymous_tmpfile (int flags,
GLnxTmpfile *out_tmpf,
GError **error)
{
- if (glnx_open_anonymous_tmpfile_full (flags, "/var/tmp", out_tmpf, error))
- return TRUE;
- else if ((*error)->code == G_IO_ERROR_NOT_FOUND)
- {
- /* If /var/tmp doesn't exist, such as in a NixOS build or
- * other constrained systems, this will fail.
- *
- * Therefore, we try again using the directory in $TMPDIR if possible.
- */
- const char *tmpdir = getenv("TMPDIR");
- if (tmpdir == NULL)
- return FALSE;
-
- GError *tmp_error;
- tmp_error = NULL;
- if (!glnx_open_anonymous_tmpfile_full (flags, tmpdir,
- out_tmpf, &tmp_error))
- {
- g_propagate_error (error, tmp_error);
- return FALSE;
- }
- else
- {
- // Don't leave the error from the first call to
- // glnx_open_anonymous_tmpfile_full in `error`.
- g_clear_error(error);
- return TRUE;
- }
- }
- else
- return FALSE;
+ return glnx_open_anonymous_tmpfile_full (flags,
+ getenv("TMPDIR") ?: "/var/tmp",
+ out_tmpf,
+ error);
}
/* Use this after calling glnx_open_tmpfile_linkable_at() to give