aboutsummaryrefslogtreecommitdiff
path: root/include/libc-internal.h
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-11-26 16:42:38 -0800
committerH.J. Lu <hjl.tools@gmail.com>2012-11-26 16:45:36 -0800
commitc515fb5148f1d81d5f7736825e14c7502c15432a (patch)
treebffe0f355bac8c00df91b12a1feddc768677bc5d /include/libc-internal.h
parent4cf77aa9847aac13bf65c977396b6e8a66337238 (diff)
downloadglibc-c515fb5148f1d81d5f7736825e14c7502c15432a.zip
glibc-c515fb5148f1d81d5f7736825e14c7502c15432a.tar.gz
glibc-c515fb5148f1d81d5f7736825e14c7502c15432a.tar.bz2
Cast to __intptr_t before casting pointer to int64
Diffstat (limited to 'include/libc-internal.h')
-rw-r--r--include/libc-internal.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/libc-internal.h b/include/libc-internal.h
index e5fd533..0c0fa02 100644
--- a/include/libc-internal.h
+++ b/include/libc-internal.h
@@ -34,4 +34,20 @@ extern void __libc_thread_freeres (void);
/* Define and initialize `__progname' et. al. */
extern void __init_misc (int, char **, char **);
+/* 1 if 'type' is a pointer type, 0 otherwise. */
+# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5)
+
+/* __intptr_t if P is true, or T if P is false. */
+# define __integer_if_pointer_type_sub(T, P) \
+ __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \
+ : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0))
+
+/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */
+# define __integer_if_pointer_type(expr) \
+ __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \
+ __pointer_type (__typeof__ (expr)))
+
+/* Cast an integer or a pointer VAL to integer with proper type. */
+# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
+
#endif /* _LIBC_INTERNAL */