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