]>
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>
33 /* read and write whole files */
34 extern int lxc_write_to_file(const char *filename
, const void *buf
,
35 size_t count
, bool add_newline
, mode_t mode
);
36 extern int lxc_read_from_file(const char *filename
, void *buf
, size_t count
);
38 /* send and receive buffers completely */
39 extern ssize_t
lxc_write_nointr(int fd
, const void *buf
, size_t count
);
40 extern ssize_t
lxc_send_nointr(int sockfd
, void *buf
, size_t len
, int flags
);
41 extern ssize_t
lxc_read_nointr(int fd
, void *buf
, size_t count
);
42 extern ssize_t
lxc_read_nointr_expect(int fd
, void *buf
, size_t count
,
43 const void *expected_buf
);
44 extern ssize_t
lxc_read_file_expect(const char *path
, void *buf
, size_t count
,
45 const void *expected_buf
);
46 extern ssize_t
lxc_recv_nointr(int sockfd
, void *buf
, size_t len
, int flags
);
47 ssize_t
lxc_recvmsg_nointr_iov(int sockfd
, struct iovec
*iov
, size_t iovlen
,
50 extern bool file_exists(const char *f
);
51 extern int print_to_file(const char *file
, const char *content
);
52 extern int is_dir(const char *path
);
53 extern int lxc_count_file_lines(const char *fn
);
54 extern int lxc_make_tmpfile(char *template, bool rm
);
56 /* __typeof__ should be safe to use with all compilers. */
57 typedef __typeof__(((struct statfs
*)NULL
)->f_type
) fs_type_magic
;
58 extern bool has_fs_type(const char *path
, fs_type_magic magic_val
);
59 extern bool fhas_fs_type(int fd
, fs_type_magic magic_val
);
60 extern bool is_fs_type(const struct statfs
*fs
, fs_type_magic magic_val
);
61 extern FILE *fopen_cloexec(const char *path
, const char *mode
);
62 extern ssize_t
lxc_sendfile_nointr(int out_fd
, int in_fd
, off_t
*offset
,
64 extern char *file_to_buf(char *path
, size_t *length
);
65 extern int fd_to_fd(int from
, int to
);
67 #endif /* __LXC_FILE_UTILS_H */