summaryrefslogtreecommitdiff
path: root/glnx-fdio.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-06-27 21:09:53 -0400
committerColin Walters <walters@verbum.org>2017-06-28 11:23:01 -0400
commite55fd8ee318b858c8fadd223157d60952746200f (patch)
treef50fe22c09389ea367a2ae18d4298b6bfa6575d5 /glnx-fdio.c
parentd4c5c02327cc3ac29e40848c53fd1bce392e8ae5 (diff)
downloadlibglnx-e55fd8ee318b858c8fadd223157d60952746200f.tar.gz
fdio: Introduce glnx_open_anonymous_tmpfile()
There was a user of this in the libostree static delta code.
Diffstat (limited to 'glnx-fdio.c')
-rw-r--r--glnx-fdio.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c
index ad43e61..c8da35e 100644
--- a/glnx-fdio.c
+++ b/glnx-fdio.c
@@ -244,6 +244,27 @@ glnx_open_tmpfile_linkable_at (int dfd,
return FALSE;
}
+/* 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.
+ */
+gboolean
+glnx_open_anonymous_tmpfile (int flags,
+ GLnxTmpfile *out_tmpf,
+ GError **error)
+{
+ if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, "/var/tmp", flags, out_tmpf, error))
+ return FALSE;
+ if (out_tmpf->path)
+ {
+ (void) unlinkat (out_tmpf->src_dfd, out_tmpf->path, 0);
+ g_clear_pointer (&out_tmpf->path, g_free);
+ }
+ out_tmpf->anonymous = TRUE;
+ out_tmpf->src_dfd = -1;
+ return TRUE;
+}
+
/* Use this after calling glnx_open_tmpfile_linkable_at() to give
* the file its final name (link into place).
*/
@@ -257,7 +278,9 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
const gboolean replace = (mode == GLNX_LINK_TMPFILE_REPLACE);
const gboolean ignore_eexist = (mode == GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST);
+ g_return_val_if_fail (!tmpf->anonymous, FALSE);
g_return_val_if_fail (tmpf->fd >= 0, FALSE);
+ g_return_val_if_fail (tmpf->src_dfd == AT_FDCWD || tmpf->src_dfd >= 0, FALSE);
/* Unlike the original systemd code, this function also supports
* replacing existing files.