aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-11-16 23:01:22 +0100
committerMattias Andrée <maandree@operamail.com>2015-11-16 23:01:22 +0100
commit8c2dc5ccec7c6726b5414a2b62a596f0531d0463 (patch)
treeb21f10236c933f9c79a2904f967fe3337fd06205 /include
parentincrease readability (diff)
downloadslibc-8c2dc5ccec7c6726b5414a2b62a596f0531d0463.tar.gz
slibc-8c2dc5ccec7c6726b5414a2b62a596f0531d0463.tar.bz2
slibc-8c2dc5ccec7c6726b5414a2b62a596f0531d0463.tar.xz
add macros for overflow check
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'include')
-rw-r--r--include/slibc/internals.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/slibc/internals.h b/include/slibc/internals.h
index 099e2e7..b3f6235 100644
--- a/include/slibc/internals.h
+++ b/include/slibc/internals.h
@@ -18,9 +18,24 @@
#ifndef _SLIBC_INTERNALS_H
#define _SLIBC_INTERNALS_H
+#include <errno.h>
+
+
#define _(msg) msg
+#define OVERFLOW(op, a, b, res, errnum, failrc) \
+ do \
+ if (__builtin_##op##_overflow(a, b, res)) \
+ return errno = (errnum), (failrc); \
+ while (0)
+
+
+#define MEM_OVERFLOW(op, a, b, res) \
+ OVERFLOW(op, a, b, res, ENOMEM, NULL)
+
+
+
#endif