aboutsummaryrefslogtreecommitdiff
path: root/libpam
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2024-08-13 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2024-08-13 08:00:00 +0000
commit10071e284ea4a496ab97b56d477e23cf09d972ec (patch)
tree882ac1bd04bb9659abb5ca9388e6febaadf71fbb /libpam
parent8ae228fa76ff9ef1d8d6b2199582d9206f1830c6 (diff)
downloadpam-10071e284ea4a496ab97b56d477e23cf09d972ec.tar.gz
pam-10071e284ea4a496ab97b56d477e23cf09d972ec.tar.bz2
pam-10071e284ea4a496ab97b56d477e23cf09d972ec.zip
pam_inline.h: introduce zero_extend_signed_to_ull() and sign_extend_unsigned_to_ll()
Import these handy macros from strace project.
Diffstat (limited to 'libpam')
-rw-r--r--libpam/include/pam_inline.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/libpam/include/pam_inline.h b/libpam/include/pam_inline.h
index a5aceb8a..cc302248 100644
--- a/libpam/include/pam_inline.h
+++ b/libpam/include/pam_inline.h
@@ -45,6 +45,26 @@
#define PAM_ARRAY_SIZE(a_) (sizeof(a_) / sizeof((a_)[0]) + PAM_MUST_BE_ARRAY(a_))
/*
+ * Zero-extend a signed integer type to unsigned long long.
+ */
+# define zero_extend_signed_to_ull(v_) \
+ (sizeof(v_) == sizeof(char) ? (unsigned long long) (unsigned char) (v_) : \
+ sizeof(v_) == sizeof(short) ? (unsigned long long) (unsigned short) (v_) : \
+ sizeof(v_) == sizeof(int) ? (unsigned long long) (unsigned int) (v_) : \
+ sizeof(v_) == sizeof(long) ? (unsigned long long) (unsigned long) (v_) : \
+ (unsigned long long) (v_))
+
+/*
+ * Sign-extend an unsigned integer type to long long.
+ */
+# define sign_extend_unsigned_to_ll(v_) \
+ (sizeof(v_) == sizeof(char) ? (long long) (signed char) (v_) : \
+ sizeof(v_) == sizeof(short) ? (long long) (signed short) (v_) : \
+ sizeof(v_) == sizeof(int) ? (long long) (signed int) (v_) : \
+ sizeof(v_) == sizeof(long) ? (long long) (signed long) (v_) : \
+ (long long) (v_))
+
+/*
* Returns NULL if STR does not start with PREFIX,
* or a pointer to the first char in STR after PREFIX.
* The length of PREFIX is specified by PREFIX_LEN.