summaryrefslogtreecommitdiffstats
path: root/kernel/tests/include/safe_macros_fn.h
blob: 3df952811b94870478dae92aceffbc713cf43f83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Safe macros for commonly used syscalls to reduce code duplication in LTP
 * testcases, and to ensure all errors are caught in said testcases as
 * gracefully as possible.
 *
 * Also satiates some versions of gcc/glibc when the warn_unused_result
 * attribute is applied to the function call.
 *
 * Licensed under the GPLv2.
 */

#ifndef SAFE_MACROS_FN_H__
#define SAFE_MACROS_FN_H__

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdarg.h>
#include <unistd.h>
#include <dirent.h>

char* safe_basename(const char *file, const int lineno,
                    void (*cleanup_fn)(void), char *path);

int safe_chdir(const char *file, const int lineno,
               void (*cleanup_fn)(void), const char *path);

int safe_close(const char *file, const int lineno,
               void (*cleanup_fn)(void), int fildes);

int safe_creat(const char *file, const int lineno,
               void (*cleanup_fn)(void), const char *pathname, mode_t mode);

char* safe_dirname(const char *file, const int lineno,
                   void (*cleanup_fn)(void), char *path);

char* safe_getcwd(const char *file, const int lineno,
                  void (*cleanup_fn)(void), char *buf, size_t size);

struct passwd* safe_getpwnam(const char *file, const int lineno,
                             void (*cleanup_fn)(void), const char *name);

int safe_getrusage(const char *file, const int lineno,
                   void (*cleanup_fn)(void), int who, struct rusage *usage);

void* safe_malloc(const char *file, const int lineno,
                  void (*cleanup_fn)(void), size_t size);

int safe_mkdir(const char *file, const int lineno,
               void (*cleanup_fn)(void), const char *pathname, mode_t mode);

int safe_rmdir(const char *file, const int lineno,
               void (*cleanup_fn)(void), const char *pathname);


int safe_munmap(const char *file, const int lineno,
                void (*cleanup_fn)(void), void *addr, size_t length);

int safe_open(const char *file, const int lineno,
              void (*cleanup_fn)(void), const char *pathname, int oflags, ...);

int safe_pipe(const char *file, const int lineno,
              void (*cleanup_fn)(void), int fildes[2]);

ssize_t safe_read(const char *file, const int lineno,
                  void (*cleanup_fn)(void), char len_strict, int fildes,
                  void *buf, size_t nbyte);

int safe_setegid(const char *file, const int lineno,
                 void (*cleanup_fn)(void), gid_t egid);

int safe_seteuid(const char *file, const int lineno,
                 void (*cleanup_fn)(void), uid_t euid);

int safe_setgid(const char *file, const int lineno,
                void (*cleanup_fn)(void), gid_t gid);

int safe_setuid(const char *file, const int lineno,
                void (*cleanup_fn)(void), uid_t uid);

int safe_getresuid(const char *file, const int lineno,
                   void (*cleanup_fn)(void),
                   uid_t *ruid, uid_t *euid, uid_t *suid);

int safe_getresgid(const char *file, const int lineno,
                   void (*cleanup_fn)(void),
                   gid_t *rgid, gid_t *egid, gid_t *sgid);

int safe_unlink(const char *file, const int lineno,
                void (*cleanup_fn)(void), const char *pathname);

int safe_link(const char *file, const int lineno,
              void (cleanup_fn)(void), const char *oldpath,
              const char *newpath);

int safe_linkat(const char *file, const int lineno,
		void (cleanup_fn)(void), int olddirfd, const char *oldpath,
		int newdirfd, const char *newpath, int flags);

ssize_t safe_readlink(const char *file, const int lineno,
		  void (cleanup_fn)(void), const char *path,
		  char *buf, size_t bufsize);

int safe_symlink(const char *file, const int lineno,
                 void (cleanup_fn)(void), const char *oldpath,
                 const char *newpath);

ssize_t safe_write(const char *file, const int lineno,
                   void (cleanup_fn)(void), char len_strict, int fildes,
                   const void *buf, size_t nbyte);

long safe_strtol(const char *file, const int lineno,
                 void (cleanup_fn)(void), char *str, long min, long max);

unsigned long safe_strtoul(const char *file, const int lineno,
                           void (cleanup_fn)(void),
                           char *str, unsigned long min, unsigned long max);

long safe_sysconf(const char *file, const int lineno,
		  void (cleanup_fn)(void), int name);

int safe_chmod(const char *file, const int lineno, void (cleanup_fn)(void),
	       const char *path, mode_t mode);

int safe_fchmod(const char *file, const int lineno, void (cleanup_fn)(void),
	        int fd, mode_t mode);

int safe_chown(const char *file, const int lineno, void (cleanup_fn)(void),
               const char *path, uid_t owner, gid_t group);

int safe_fchown(const char *file, const int lineno, void (cleanup_fn)(void),
                int fd, uid_t owner, gid_t group);

pid_t safe_wait(const char *file, const int lineno, void (cleanup_fn)(void),
                int *status);

pid_t safe_waitpid(const char *file, const int lineno, void (cleanup_fn)(void),
                   pid_t pid, int *status, int opts);

int safe_kill(const char *file, const int lineno, void (cleanup_fn)(void),
              pid_t pid, int sig);

void *safe_memalign(const char *file, const int lineno,
		    void (*cleanup_fn)(void), size_t alignment, size_t size);

int safe_mkfifo(const char *file, const int lineno,
		void (*cleanup_fn)(void), const char *pathname, mode_t mode);

int safe_rename(const char *file, const int lineno, void (*cleanup_fn)(void),
		const char *oldpath, const char *newpath);

int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
	       const char *source, const char *target,
	       const char *filesystemtype, unsigned long mountflags,
	       const void *data);

int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
		const char *target);

DIR* safe_opendir(const char *file, const int lineno, void (cleanup_fn)(void),
                  const char *name);

int safe_closedir(const char *file, const int lineno, void (cleanup_fn)(void),
                  DIR *dirp);

struct dirent *safe_readdir(const char *file, const int lineno,
                            void (cleanup_fn)(void),
                            DIR *dirp);

DIR* safe_opendir(const char *file, const int lineno,
                  void (cleanup_fn)(void),
                  const char *name);

struct dirent *safe_readdir(const char *file, const int lineno,
                            void (cleanup_fn)(void),
                            DIR *dirp);

int safe_closedir(const char *file, const int lineno,
                  void (cleanup_fn)(void),
                  DIR *dirp);

#endif /* SAFE_MACROS_FN_H__ */