]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/file_utils.h
compiler: support new access attributes
[mirror_lxc.git] / src / lxc / file_utils.h
index 7ae28697530128e619af40c1a8069efbb71cda29..f9c8abe0335246bbc697dc2adb2821623476d312 100644 (file)
@@ -1,47 +1,65 @@
-/* liblxcapi
- *
- * Copyright © 2018 Christian Brauner <christian.brauner@ubuntu.com>.
- * Copyright © 2018 Canonical Ltd.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2, as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
+/* SPDX-License-Identifier: LGPL-2.1+ */
 
 #ifndef __LXC_FILE_UTILS_H
 #define __LXC_FILE_UTILS_H
 
-#include "config.h"
-
 #include <fcntl.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/uio.h>
 #include <sys/vfs.h>
 #include <unistd.h>
 
+#include "compiler.h"
+
 /* read and write whole files */
 extern int lxc_write_to_file(const char *filename, const void *buf,
-                            size_t count, bool add_newline, mode_t mode);
-extern int lxc_read_from_file(const char *filename, void *buf, size_t count);
+                            size_t count, bool add_newline, mode_t mode)
+__access_r(2, 3);
+
+extern int lxc_readat(int dirfd, const char *filename, void *buf, size_t count)
+__access_w(3, 4);
+
+extern int lxc_writeat(int dirfd, const char *filename, const void *buf,
+                      size_t count)
+__access_r(3, 4);
+
+extern int lxc_write_openat(const char *dir, const char *filename,
+                           const void *buf, size_t count)
+__access_r(3, 4);
+
+extern int lxc_read_from_file(const char *filename, void *buf, size_t count)
+__access_w(2, 3);
 
 /* send and receive buffers completely */
-extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count);
-extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags);
-extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count);
+extern ssize_t lxc_write_nointr(int fd, const void *buf, size_t count)
+__access_r(2, 3);
+
+extern ssize_t lxc_pwrite_nointr(int fd, const void *buf, size_t count,
+                                off_t offset)
+__access_r(2, 3);
+
+extern ssize_t lxc_send_nointr(int sockfd, void *buf, size_t len, int flags)
+__access_r(2, 3);
+
+extern ssize_t lxc_read_nointr(int fd, void *buf, size_t count)
+__access_w(2, 3);
+
 extern ssize_t lxc_read_nointr_expect(int fd, void *buf, size_t count,
-                                     const void *expected_buf);
-extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags);
+                                     const void *expected_buf)
+__access_w(2, 3);
+
+extern ssize_t lxc_read_file_expect(const char *path, void *buf, size_t count,
+                                     const void *expected_buf)
+__access_w(2, 3);
+
+extern ssize_t lxc_recv_nointr(int sockfd, void *buf, size_t len, int flags)
+__access_w(2, 3);
+
+ssize_t lxc_recvmsg_nointr_iov(int sockfd, struct iovec *iov, size_t iovlen,
+                              int flags);
 
 extern bool file_exists(const char *f);
 extern int print_to_file(const char *file, const char *content);
@@ -55,5 +73,14 @@ extern bool has_fs_type(const char *path, fs_type_magic magic_val);
 extern bool fhas_fs_type(int fd, fs_type_magic magic_val);
 extern bool is_fs_type(const struct statfs *fs, fs_type_magic magic_val);
 extern FILE *fopen_cloexec(const char *path, const char *mode);
+extern ssize_t lxc_sendfile_nointr(int out_fd, int in_fd, off_t *offset,
+                                  size_t count);
+extern char *file_to_buf(const char *path, size_t *length);
+extern int fd_to_buf(int fd, char **buf, size_t *length);
+extern int fd_to_fd(int from, int to);
+extern int lxc_open_dirfd(const char *dir);
+extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer);
+extern FILE *fopen_cached(const char *path, const char *mode,
+                         void **caller_freed_buffer);
 
 #endif /* __LXC_FILE_UTILS_H */