diff options
-rw-r--r-- | glnx-fdio.c | 29 | ||||
-rw-r--r-- | glnx-fdio.h | 7 | ||||
-rw-r--r-- | glnx-macros.h | 10 | ||||
-rw-r--r-- | glnx-missing.h | 1 |
4 files changed, 40 insertions, 7 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c index 7b734ff..1dc5ffd 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -277,17 +277,19 @@ glnx_open_tmpfile_linkable_at (int dfd, return open_tmpfile_core (dfd, subpath, flags, out_tmpf, error); } + /* 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 to - * ensure maximum storage space. + * Useful for true temporary storage. The fd will be allocated in the specified + * directory. */ gboolean -glnx_open_anonymous_tmpfile (int flags, - GLnxTmpfile *out_tmpf, - GError **error) +glnx_open_anonymous_tmpfile_full (int flags, + const char *dir, + GLnxTmpfile *out_tmpf, + GError **error) { /* Add in O_EXCL */ - if (!open_tmpfile_core (AT_FDCWD, "/var/tmp", flags | O_EXCL, out_tmpf, error)) + if (!open_tmpfile_core (AT_FDCWD, dir, flags | O_EXCL, out_tmpf, error)) return FALSE; if (out_tmpf->path) { @@ -299,6 +301,21 @@ glnx_open_anonymous_tmpfile (int flags, return TRUE; } +/* 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 to + * ensure maximum storage space. + * + * If you need the file on a specific filesystem use glnx_open_anonymous_tmpfile_full() + * which lets you pass a directory. + */ +gboolean +glnx_open_anonymous_tmpfile (int flags, + GLnxTmpfile *out_tmpf, + GError **error) +{ + return glnx_open_anonymous_tmpfile_full (flags, "/var/tmp", out_tmpf, error); +} + /* Use this after calling glnx_open_tmpfile_linkable_at() to give * the file its final name (link into place). */ diff --git a/glnx-fdio.h b/glnx-fdio.h index c0a7cc1..d97ea36 100644 --- a/glnx-fdio.h +++ b/glnx-fdio.h @@ -84,6 +84,13 @@ glnx_open_anonymous_tmpfile (int flags, GError **error); gboolean +glnx_open_anonymous_tmpfile_full (int flags, + const char *dir, + GLnxTmpfile *out_tmpf, + GError **error); + + +gboolean glnx_open_tmpfile_linkable_at (int dfd, const char *subpath, int flags, diff --git a/glnx-macros.h b/glnx-macros.h index 6d8aca9..700fc75 100644 --- a/glnx-macros.h +++ b/glnx-macros.h @@ -31,6 +31,16 @@ G_BEGIN_DECLS /* All of these are for C only. */ #ifndef __GI_SCANNER__ +/* fixes builds against musl, taken from glibc unistd.h */ +#ifndef TEMP_FAILURE_RETRY +#define TEMP_FAILURE_RETRY(expression) \ + (__extension__ \ + ({ long int __result; \ + do __result = (long int) (expression); \ + while (__result == -1L && errno == EINTR); \ + __result; })) +#endif + /* Taken from https://github.com/systemd/systemd/src/basic/string-util.h * at revision v228-666-gcf6c8c4 */ diff --git a/glnx-missing.h b/glnx-missing.h index 0eba07b..9d35c40 100644 --- a/glnx-missing.h +++ b/glnx-missing.h @@ -36,7 +36,6 @@ #include <stdlib.h> #include <sys/resource.h> #include <sys/syscall.h> -#include <uchar.h> #include <unistd.h> /* The precise definition of __O_TMPFILE is arch specific; use the |