lib: Add a helper for mmap->bytes with openat(), use it in repo
This kills another GSystem consumer...I think down the line I'd like to do something like "detect whether file is > 1k if so, mmap, otherwise just readall()" so we can use this helper in more places. Closes: #319 Approved by: jlebon
This commit is contained in:
1 parent
3a03a35071
commit
70e5489258
3 files changed
+26
-3
No files matched your search
@@ -230,3 +230,24 @@ ot_openat_ignore_enoent (int dfd,
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
GBytes *
|
||||
ot_file_mapat_bytes (int dfd,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
glnx_fd_close int fd = openat (dfd, path, O_RDONLY | O_CLOEXEC);
|
||||
g_autoptr(GMappedFile) mfile = NULL;
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
||||
if (!mfile)
|
||||
return FALSE;
|
||||
|
||||
return g_mapped_file_get_bytes (mfile);
|
||||
}
|
||||
@@ -66,4 +66,8 @@ gboolean ot_openat_ignore_enoent (int dfd,
|
||||
int *out_fd,
|
||||
GError **error);
|
||||
|
||||
GBytes *ot_file_mapat_bytes (int dfd,
|
||||
const char *path,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
Reference in new issue
Block a user