]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/file_utils.h
CVE-2019-5736 (runC): rexec callers as memfd
[mirror_lxc.git] / src / lxc / file_utils.h
1 /* liblxcapi
2 *
3 * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
4 * Copyright © 2018 Canonical Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef __LXC_FILE_UTILS_H
21 #define __LXC_FILE_UTILS_H
22
23 #include <fcntl.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <sys/vfs.h>
29 #include <unistd.h>
30
31 /* read and write whole files */
32 extern int lxc_write_to_file(const char *filename, const void *buf,
33 size_t count, bool add_newline, mode_t mode);
34 extern int lxc_read_from_file(const char *filename, void *buf, size_t count);
35
36 /* send and receive buffers completely */
37 extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count);
38 extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags);
39 extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count);
40 extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
41 const void *expected_buf);
42 extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags);
43
44 extern bool file_exists(const char *f);
45 extern int print_to_file(const char *file, const char *content);
46 extern int is_dir(const char *path);
47 extern int lxc_count_file_lines(const char *fn);
48 extern int lxc_make_tmpfile(char *template, bool rm);
49
50 /* __typeof__ should be safe to use with all compilers. */
51 typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
52 extern bool has_fs_type(const char *path, fs_type_magic magic_val);
53 extern bool fhas_fs_type(int fd, fs_type_magic magic_val);
54 extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
55 extern FILE *fopen_cloexec(const char *path, const char *mode);
56 extern ssize_t lxc_sendfile_nointr(int out_fd, int in_fd, off_t *offset,
57 size_t count);
58 extern char *file_to_buf(char *path, size_t *length);
59
60 #endif /* __LXC_FILE_UTILS_H */