]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/file_utils.h
utils: split into {file,string}_utils.{c,h}
[mirror_lxc.git] / src / lxc / file_utils.h
CommitLineData
37ef15bb
CB
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 "config.h"
24
25#include <fcntl.h>
26#include <stdbool.h>
27#include <stdio.h>
28#include <sys/stat.h>
29#include <sys/types.h>
30#include <sys/vfs.h>
31#include <unistd.h>
32
33/* read and write whole files */
34extern int lxc_write_to_file(const char *filename, const void *buf,
35 size_t count, bool add_newline, mode_t mode);
36extern int lxc_read_from_file(const char *filename, void *buf, size_t count);
37
38/* send and receive buffers completely */
39extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count);
40extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count);
41extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
42 const void *expected_buf);
43extern bool file_exists(const char *f);
44extern int print_to_file(const char *file, const char *content);
45extern int is_dir(const char *path);
46extern int lxc_count_file_lines(const char *fn);
47extern int lxc_make_tmpfile(char *template, bool rm);
48
49/* __typeof__ should be safe to use with all compilers. */
50typedef __typeof__(((struct statfs *)NULL)->f_type) fs_type_magic;
51extern bool has_fs_type(const char *path, fs_type_magic magic_val);
52extern bool fhas_fs_type(int fd, fs_type_magic magic_val);
53extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
54extern FILE *fopen_cloexec(const char *path, const char *mode);
55
56#endif /* __LXC_FILE_UTILS_H */