• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdarg.h>
11 
12 #define SAFE_OPENAT(dirfd, path, oflags, ...)			\
13 	safe_openat(__FILE__, __LINE__,				\
14 		    (dirfd), (path), (oflags), ## __VA_ARGS__)
15 
16 #define SAFE_FILE_READAT(dirfd, path, buf, nbyte)			\
17 	safe_file_readat(__FILE__, __LINE__,				\
18 			 (dirfd), (path), (buf), (nbyte))
19 
20 
21 #define SAFE_FILE_PRINTFAT(dirfd, path, fmt, ...)			\
22 	safe_file_printfat(__FILE__, __LINE__,				\
23 			   (dirfd), (path), (fmt), __VA_ARGS__)
24 
25 #define SAFE_UNLINKAT(dirfd, path, flags)				\
26 	safe_unlinkat(__FILE__, __LINE__, (dirfd), (path), (flags))
27 
28 const char *tst_decode_fd(const int fd)
29 			  __attribute__((warn_unused_result));
30 
31 int safe_openat(const char *const file, const int lineno, const int dirfd,
32                 const char *const path, const int oflags, ...)
33 		__attribute__((nonnull, warn_unused_result));
34 
35 ssize_t safe_file_readat(const char *const file, const int lineno,
36 			 const int dirfd, const char *const path,
37 			 char *const buf, const size_t nbyte)
38 			 __attribute__ ((nonnull));
39 
40 int tst_file_vprintfat(const int dirfd, const char *const path,
41 		       const char *const fmt, va_list va)
42 		       __attribute__((nonnull));
43 int tst_file_printfat(const int dirfd, const char *const path,
44 		      const char *const fmt, ...)
45 		      __attribute__ ((format (printf, 3, 4), nonnull));
46 
47 int safe_file_vprintfat(const char *const file, const int lineno,
48 			const int dirfd, const char *const path,
49 			const char *const fmt, va_list va)
50 			__attribute__ ((nonnull));
51 
52 int safe_file_printfat(const char *const file, const int lineno,
53 		       const int dirfd, const char *const path,
54 		       const char *const fmt, ...)
55 		       __attribute__ ((format (printf, 5, 6), nonnull));
56 
57 int safe_unlinkat(const char *const file, const int lineno,
58 		  const int dirfd, const char *const path, const int flags)
59 		  __attribute__ ((nonnull));
60 
61 #endif
62