1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com> 4 */ 5 6 #ifndef TST_SAFE_FILE_AT_H 7 #define TST_SAFE_FILE_AT_H 8 9 #include <sys/types.h> 10 #include <sys/stat.h> 11 #include <unistd.h> 12 #include <stdarg.h> 13 14 #define SAFE_OPENAT(dirfd, path, oflags, ...) \ 15 safe_openat(__FILE__, __LINE__, \ 16 (dirfd), (path), (oflags), ## __VA_ARGS__) 17 18 #define SAFE_FILE_READAT(dirfd, path, buf, nbyte) \ 19 safe_file_readat(__FILE__, __LINE__, \ 20 (dirfd), (path), (buf), (nbyte)) 21 22 23 #define SAFE_FILE_PRINTFAT(dirfd, path, fmt, ...) \ 24 safe_file_printfat(__FILE__, __LINE__, \ 25 (dirfd), (path), (fmt), __VA_ARGS__) 26 27 #define SAFE_UNLINKAT(dirfd, path, flags) \ 28 safe_unlinkat(__FILE__, __LINE__, (dirfd), (path), (flags)) 29 30 #define SAFE_FCHOWNAT(dirfd, path, owner, group, flags) \ 31 safe_fchownat(__FILE__, __LINE__, \ 32 (dirfd), (path), (owner), (group), (flags)) 33 34 #define SAFE_FSTATAT(dirfd, path, statbuf, flags) \ 35 safe_fstatat(__FILE__, __LINE__, (dirfd), (path), (statbuf), (flags)) 36 37 const char *tst_decode_fd(const int fd) 38 __attribute__((warn_unused_result)); 39 40 int safe_openat(const char *const file, const int lineno, const int dirfd, 41 const char *const path, const int oflags, ...) 42 __attribute__((nonnull, warn_unused_result)); 43 44 ssize_t safe_file_readat(const char *const file, const int lineno, 45 const int dirfd, const char *const path, 46 char *const buf, const size_t nbyte) 47 __attribute__ ((nonnull)); 48 49 int tst_file_vprintfat(const int dirfd, const char *const path, 50 const char *const fmt, va_list va) 51 __attribute__((nonnull)); 52 int tst_file_printfat(const int dirfd, const char *const path, 53 const char *const fmt, ...) 54 __attribute__ ((format (printf, 3, 4), nonnull)); 55 56 int safe_file_vprintfat(const char *const file, const int lineno, 57 const int dirfd, const char *const path, 58 const char *const fmt, va_list va) 59 __attribute__ ((nonnull)); 60 61 int safe_file_printfat(const char *const file, const int lineno, 62 const int dirfd, const char *const path, 63 const char *const fmt, ...) 64 __attribute__ ((format (printf, 5, 6), nonnull)); 65 66 int safe_unlinkat(const char *const file, const int lineno, 67 const int dirfd, const char *const path, const int flags) 68 __attribute__ ((nonnull)); 69 70 int safe_fchownat(const char *const file, const int lineno, 71 const int dirfd, const char *const path, uid_t owner, 72 gid_t group, int flags) 73 __attribute__ ((nonnull)); 74 75 int safe_fstatat(const char *const file, const int lineno, 76 const int dirfd, const char *const path, struct stat *statbuf, 77 int flags) 78 __attribute__ ((nonnull)); 79 #endif 80