diff options
| author | Jakob Kaivo <jkk@ung.org> | 2019-01-26 22:41:05 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2019-01-26 22:41:05 -0500 |
| commit | 8c6d4505329f94446084ca93eae10cd796d79a8d (patch) | |
| tree | c00c6a990c81bd771ebcac72b38fd3ce2382c42e /nonstd/syscall.h | |
new framework for building sources after gitlab migration
Diffstat (limited to 'nonstd/syscall.h')
| -rw-r--r-- | nonstd/syscall.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/nonstd/syscall.h b/nonstd/syscall.h new file mode 100644 index 00000000..e77ceeaa --- /dev/null +++ b/nonstd/syscall.h @@ -0,0 +1,38 @@ +#ifndef __NONSTD_SYSCALL_H__ +#define __NONSTD_SYSCALL_H__ + +#include <errno.h> +#include "nonstd/types.h" + +#ifndef ENOSYS +#define ENOSYS 10 +#endif + +#define SCNO(_var, _name, _notfound) static int _var = -2; do { \ + if ((_var) == -2) { (_var) = __libc.syscall_lookup((_name)); } \ + if ((_var) == -1) { errno = ENOSYS; return (_notfound); } \ + } while (0) + +#define SCNOFAIL() static int _scno = -2; \ + if (_scno == -2) { _scno = __libc.syscall_lookup(__func__); } \ + return __libc.syscall(_scno) + +#define SC(_type, ...) static int _scno = -2; \ + if (_scno == -2) { _scno = __libc.syscall_lookup(__func__); } \ + _type _ret = __libc.syscall(_scno, __VA_ARGS__); \ + if (_ret < 0) { \ + errno = -_ret; \ + return -1; \ + } \ + return _ret + +#define SC0(_type) static int _scno = -2; \ + if (_scno == -2) { _scno = __libc.syscall_lookup(__func__); } \ + _type __ret = __libc.syscall(_scno); \ + if (_ret < 0) { \ + errno = -_ret; \ + return -1; \ + } \ + return _ret + +#endif |
