Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
steam-runtime-tools
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Contributor analytics
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
a3714b89
Commit
a3714b89
authored
4 years ago
by
Simon McVittie
Browse files
Options
Downloads
Patches
Plain Diff
_srt_file_get_contents_in_sysroot: Add
Signed-off-by:
Simon McVittie
<
smcv@collabora.com
>
parent
86d837c5
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!139
Move resolve-in-sysroot into the shared library
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
steam-runtime-tools/utils-internal.h
+7
-0
7 additions, 0 deletions
steam-runtime-tools/utils-internal.h
steam-runtime-tools/utils.c
+55
-0
55 additions, 0 deletions
steam-runtime-tools/utils.c
with
62 additions
and
0 deletions
steam-runtime-tools/utils-internal.h
+
7
−
0
View file @
a3714b89
...
...
@@ -87,3 +87,10 @@ gchar ** _srt_json_array_to_strv (JsonObject *json_obj,
gboolean
_srt_rm_rf
(
const
char
*
directory
);
FILE
*
_srt_divert_stdout_to_stderr
(
GError
**
error
);
G_GNUC_INTERNAL
gboolean
_srt_file_get_contents_in_sysroot
(
int
sysroot_fd
,
const
char
*
path
,
gchar
**
contents
,
gsize
*
len
,
GError
**
error
);
This diff is collapsed.
Click to expand it.
steam-runtime-tools/utils.c
+
55
−
0
View file @
a3714b89
...
...
@@ -44,6 +44,7 @@
#include
<glib-object.h>
#include
<gio/gio.h>
#include
"steam-runtime-tools/glib-backports-internal.h"
#include
"steam-runtime-tools/resolve-in-sysroot-internal.h"
#ifdef HAVE_GETAUXVAL
#define getauxval_AT_SECURE() getauxval (AT_SECURE)
...
...
@@ -862,3 +863,57 @@ _srt_divert_stdout_to_stderr (GError **error)
return
g_steal_pointer
(
&
original_stdout
);
}
/*
* _srt_file_get_contents_in_sysroot:
* @sysroot_fd: A directory fd opened on the sysroot or `/`
* @path: Absolute or root-relative path within @sysroot_fd
* @contents: (out) (not optional): Used to return contents
* @len: (out) (optional): Used to return length
* @error: Used to return error on failure
*
* Like g_file_get_contents(), but the file is in a sysroot, and we
* follow symlinks as though @sysroot_fd was the root directory
* (similar to `fakechroot`).
*
* Returns: %TRUE if successful
*/
gboolean
_srt_file_get_contents_in_sysroot
(
int
sysroot_fd
,
const
char
*
path
,
gchar
**
contents
,
gsize
*
len
,
GError
**
error
)
{
g_autofree
gchar
*
real_path
=
NULL
;
g_autofree
gchar
*
fd_path
=
NULL
;
g_autofree
gchar
*
ignored
=
NULL
;
glnx_autofd
int
fd
=
-
1
;
g_return_val_if_fail
(
sysroot_fd
>=
0
,
FALSE
);
g_return_val_if_fail
(
path
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
contents
!=
NULL
,
FALSE
);
g_return_val_if_fail
(
error
==
NULL
||
*
error
==
NULL
,
FALSE
);
if
(
contents
==
NULL
)
contents
=
&
ignored
;
fd
=
_srt_resolve_in_sysroot
(
sysroot_fd
,
path
,
SRT_RESOLVE_FLAGS_READABLE
,
&
real_path
,
error
);
if
(
fd
<
0
)
return
FALSE
;
fd_path
=
g_strdup_printf
(
"/proc/self/fd/%d"
,
fd
);
if
(
!
g_file_get_contents
(
fd_path
,
contents
,
len
,
error
))
{
g_prefix_error
(
error
,
"Unable to read %s: "
,
real_path
);
return
FALSE
;
}
return
TRUE
;
}
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