Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steamrt
steam-runtime-tools
Commits
e55fd8ee
Commit
e55fd8ee
authored
7 years ago
by
Colin Walters
Browse files
Options
Downloads
Patches
Plain Diff
fdio: Introduce glnx_open_anonymous_tmpfile()
There was a user of this in the libostree static delta code.
parent
d4c5c023
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
glnx-fdio.c
+23
-0
23 additions, 0 deletions
glnx-fdio.c
glnx-fdio.h
+6
-0
6 additions, 0 deletions
glnx-fdio.h
with
29 additions
and
0 deletions
glnx-fdio.c
+
23
−
0
View file @
e55fd8ee
...
@@ -244,6 +244,27 @@ glnx_open_tmpfile_linkable_at (int dfd,
...
@@ -244,6 +244,27 @@ glnx_open_tmpfile_linkable_at (int dfd,
return
FALSE
;
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
/* Use this after calling glnx_open_tmpfile_linkable_at() to give
* the file its final name (link into place).
* the file its final name (link into place).
*/
*/
...
@@ -257,7 +278,9 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
...
@@ -257,7 +278,9 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
const
gboolean
replace
=
(
mode
==
GLNX_LINK_TMPFILE_REPLACE
);
const
gboolean
replace
=
(
mode
==
GLNX_LINK_TMPFILE_REPLACE
);
const
gboolean
ignore_eexist
=
(
mode
==
GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST
);
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
->
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
/* Unlike the original systemd code, this function also supports
* replacing existing files.
* replacing existing files.
...
...
This diff is collapsed.
Click to expand it.
glnx-fdio.h
+
6
−
0
View file @
e55fd8ee
...
@@ -52,6 +52,7 @@ const char *glnx_basename (const char *path)
...
@@ -52,6 +52,7 @@ const char *glnx_basename (const char *path)
typedef
struct
{
typedef
struct
{
gboolean
initialized
;
gboolean
initialized
;
gboolean
anonymous
;
int
src_dfd
;
int
src_dfd
;
int
fd
;
int
fd
;
char
*
path
;
char
*
path
;
...
@@ -59,6 +60,11 @@ typedef struct {
...
@@ -59,6 +60,11 @@ typedef struct {
void
glnx_tmpfile_clear
(
GLnxTmpfile
*
tmpf
);
void
glnx_tmpfile_clear
(
GLnxTmpfile
*
tmpf
);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
(
GLnxTmpfile
,
glnx_tmpfile_clear
);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
(
GLnxTmpfile
,
glnx_tmpfile_clear
);
gboolean
glnx_open_anonymous_tmpfile
(
int
flags
,
GLnxTmpfile
*
out_tmpf
,
GError
**
error
);
gboolean
gboolean
glnx_open_tmpfile_linkable_at
(
int
dfd
,
glnx_open_tmpfile_linkable_at
(
int
dfd
,
const
char
*
subpath
,
const
char
*
subpath
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment