]>
Commit | Line | Data |
---|---|---|
cc73685d | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
37ef15bb CB |
2 | |
3 | #ifndef __LXC_FILE_UTILS_H | |
4 | #define __LXC_FILE_UTILS_H | |
5 | ||
37ef15bb CB |
6 | #include <fcntl.h> |
7 | #include <stdbool.h> | |
8 | #include <stdio.h> | |
9 | #include <sys/stat.h> | |
10 | #include <sys/types.h> | |
99d03dec | 11 | #include <sys/uio.h> |
37ef15bb CB |
12 | #include <sys/vfs.h> |
13 | #include <unistd.h> | |
14 | ||
674c9692 CB |
15 | #include "compiler.h" |
16 | ||
37ef15bb | 17 | /* read and write whole files */ |
4a9ee78a CB |
18 | __hidden extern int lxc_write_to_file(const char *filename, const void *buf, size_t count, |
19 | bool add_newline, mode_t mode) __access_r(2, 3); | |
674c9692 | 20 | |
4a9ee78a CB |
21 | __hidden extern int lxc_readat(int dirfd, const char *filename, void *buf, size_t count) |
22 | __access_w(3, 4); | |
674c9692 | 23 | |
4a9ee78a CB |
24 | __hidden extern int lxc_writeat(int dirfd, const char *filename, const void *buf, size_t count) |
25 | __access_r(3, 4); | |
674c9692 | 26 | |
4a9ee78a CB |
27 | __hidden extern int lxc_write_openat(const char *dir, const char *filename, const void *buf, |
28 | size_t count) __access_r(3, 4); | |
674c9692 | 29 | |
4a9ee78a CB |
30 | __hidden extern int lxc_read_from_file(const char *filename, void *buf, size_t count) |
31 | __access_w(2, 3); | |
37ef15bb CB |
32 | |
33 | /* send and receive buffers completely */ | |
4a9ee78a | 34 | __hidden extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count) __access_r(2, 3); |
674c9692 | 35 | |
4a9ee78a CB |
36 | __hidden extern ssize_t lxc_pwrite_nointr(int fd, const void *buf, size_t count, off_t offset) |
37 | __access_r(2, 3); | |
674c9692 | 38 | |
4a9ee78a CB |
39 | __hidden extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags) |
40 | __access_r(2, 3); | |
674c9692 | 41 | |
4a9ee78a | 42 | __hidden extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count) __access_w(2, 3); |
674c9692 | 43 | |
4a9ee78a CB |
44 | __hidden extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count, |
45 | const void *expected_buf) __access_w(2, 3); | |
674c9692 | 46 | |
4a9ee78a CB |
47 | __hidden extern ssize_t lxc_read_file_expect(const char *path, void *buf, size_t count, |
48 | const void *expected_buf) __access_w(2, 3); | |
674c9692 | 49 | |
4a9ee78a CB |
50 | __hidden extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags) |
51 | __access_w(2, 3); | |
674c9692 | 52 | |
4a9ee78a CB |
53 | __hidden extern ssize_t lxc_recvmsg_nointr_iov(int sockfd, struct iovec *iov, size_t iovlen, |
54 | int flags); | |
de69edd1 | 55 | |
4a9ee78a CB |
56 | __hidden extern bool file_exists(const char *f); |
57 | __hidden extern int print_to_file(const char *file, const char *content); | |
58 | __hidden extern int is_dir(const char *path); | |
59 | __hidden extern int lxc_count_file_lines(const char *fn); | |
60 | __hidden extern int lxc_make_tmpfile(char *template, bool rm); | |
37ef15bb CB |
61 | |
62 | /* __typeof__ should be safe to use with all compilers. */ | |
63 | typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic; | |
4a9ee78a CB |
64 | __hidden extern bool has_fs_type(const char *path, fs_type_magic magic_val); |
65 | __hidden extern bool fhas_fs_type(int fd, fs_type_magic magic_val); | |
66 | __hidden extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val); | |
67 | __hidden extern FILE *fopen_cloexec(const char *path, const char *mode); | |
68 | __hidden extern ssize_t lxc_sendfile_nointr(int out_fd, int in_fd, off_t *offset, size_t count); | |
69 | __hidden extern char *file_to_buf(const char *path, size_t *length); | |
70 | __hidden extern int fd_to_buf(int fd, char **buf, size_t *length); | |
71 | __hidden extern int fd_to_fd(int from, int to); | |
72 | __hidden extern int lxc_open_dirfd(const char *dir); | |
73 | __hidden extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer); | |
74 | __hidden extern FILE *fopen_cached(const char *path, const char *mode, void **caller_freed_buffer); | |
75 | __hidden extern int timens_offset_write(clockid_t clk_id, int64_t s_offset, int64_t ns_offset); | |
37ef15bb CB |
76 | |
77 | #endif /* __LXC_FILE_UTILS_H */ |