Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
7166ab75
Unverified
Commit
7166ab75
authored
Feb 01, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file_utils: add open_at()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
42673edd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
file_utils.c
src/lxc/file_utils.c
+7
-5
file_utils.h
src/lxc/file_utils.h
+11
-1
No files found.
src/lxc/file_utils.c
View file @
7166ab75
...
@@ -621,22 +621,24 @@ bool exists_file_at(int dir_fd, const char *path)
...
@@ -621,22 +621,24 @@ bool exists_file_at(int dir_fd, const char *path)
return
fstatat
(
dir_fd
,
path
,
&
sb
,
0
)
==
0
;
return
fstatat
(
dir_fd
,
path
,
&
sb
,
0
)
==
0
;
}
}
int
open_beneath
(
int
dir_fd
,
const
char
*
path
,
unsigned
int
flags
)
int
open_at
(
int
dfd
,
const
char
*
path
,
mode_t
mode
,
unsigned
int
o_flags
,
unsigned
int
resolve_flags
)
{
{
__do_close
int
fd
=
-
EBADF
;
__do_close
int
fd
=
-
EBADF
;
struct
lxc_open_how
how
=
{
struct
lxc_open_how
how
=
{
.
flags
=
flags
,
.
flags
=
o_flags
,
.
resolve
=
RESOLVE_NO_XDEV
|
RESOLVE_NO_SYMLINKS
|
RESOLVE_NO_MAGICLINKS
|
RESOLVE_BENEATH
,
.
mode
=
mode
,
.
resolve
=
resolve_flags
,
};
};
fd
=
openat2
(
d
ir_
fd
,
path
,
&
how
,
sizeof
(
how
));
fd
=
openat2
(
dfd
,
path
,
&
how
,
sizeof
(
how
));
if
(
fd
>=
0
)
if
(
fd
>=
0
)
return
move_fd
(
fd
);
return
move_fd
(
fd
);
if
(
errno
!=
ENOSYS
)
if
(
errno
!=
ENOSYS
)
return
-
errno
;
return
-
errno
;
return
openat
(
d
ir_fd
,
path
,
O_NOFOLLOW
|
flags
);
return
openat
(
d
fd
,
path
,
O_NOFOLLOW
|
o_
flags
);
}
}
int
fd_make_nonblocking
(
int
fd
)
int
fd_make_nonblocking
(
int
fd
)
...
...
src/lxc/file_utils.h
View file @
7166ab75
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include <unistd.h>
#include <unistd.h>
#include "compiler.h"
#include "compiler.h"
#include "syscall_wrappers.h"
/* read and write whole files */
/* read and write whole files */
__hidden
extern
int
lxc_write_to_file
(
const
char
*
filename
,
const
void
*
buf
,
size_t
count
,
__hidden
extern
int
lxc_write_to_file
(
const
char
*
filename
,
const
void
*
buf
,
size_t
count
,
...
@@ -81,7 +82,16 @@ __hidden extern FILE *fopen_cached(const char *path, const char *mode, void **ca
...
@@ -81,7 +82,16 @@ __hidden extern FILE *fopen_cached(const char *path, const char *mode, void **ca
__hidden
extern
int
timens_offset_write
(
clockid_t
clk_id
,
int64_t
s_offset
,
int64_t
ns_offset
);
__hidden
extern
int
timens_offset_write
(
clockid_t
clk_id
,
int64_t
s_offset
,
int64_t
ns_offset
);
__hidden
extern
bool
exists_dir_at
(
int
dir_fd
,
const
char
*
path
);
__hidden
extern
bool
exists_dir_at
(
int
dir_fd
,
const
char
*
path
);
__hidden
extern
bool
exists_file_at
(
int
dir_fd
,
const
char
*
path
);
__hidden
extern
bool
exists_file_at
(
int
dir_fd
,
const
char
*
path
);
__hidden
extern
int
open_beneath
(
int
dir_fd
,
const
char
*
path
,
unsigned
int
flags
);
__hidden
extern
int
open_at
(
int
dfd
,
const
char
*
path
,
mode_t
mode
,
unsigned
int
o_flags
,
unsigned
int
resolve_flags
);
static
inline
int
open_beneath
(
int
dfd
,
const
char
*
path
,
unsigned
int
flags
)
{
return
open_at
(
dfd
,
path
,
0
,
flags
,
RESOLVE_NO_XDEV
|
RESOLVE_NO_SYMLINKS
|
RESOLVE_NO_MAGICLINKS
|
RESOLVE_BENEATH
);
}
__hidden
int
fd_make_nonblocking
(
int
fd
);
__hidden
int
fd_make_nonblocking
(
int
fd
);
__hidden
extern
char
*
read_file_at
(
int
dfd
,
const
char
*
fnam
);
__hidden
extern
char
*
read_file_at
(
int
dfd
,
const
char
*
fnam
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment