aboutsummaryrefslogtreecommitdiff
path: root/st.h
diff options
context:
space:
mode:
Diffstat (limited to 'st.h')
-rw-r--r--st.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/st.h b/st.h
index adec5e4..326f644 100644
--- a/st.h
+++ b/st.h
@@ -1,5 +1,5 @@
-/* See LICENSE for license details. */
-
+// Copyright 2024 @waffle87
+// SPDX-License-Identifier: MIT/X
#include <stdint.h>
#include <sys/types.h>
@@ -8,9 +8,22 @@
#define ESC_BUF_SIZ (128 * UTF_SIZ)
/* macros */
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define MAX(a, b) ((a) < (b) ? (b) : (a))
-#define LEN(a) (sizeof(a) / sizeof(a)[0])
+#define MIN(a, b) \
+ ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a < _b ? _a : _b; \
+ })
+#define MAX(a, b) \
+ ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a > _b ? _a : _b; \
+ })
+#define CHECK(value) \
+ (!__builtin_types_compatible_p(typeof((value)), typeof(&(value)[0])))
+#define LEN(a) \
+ (__builtin_choose_expr(CHECK((a)), sizeof((a)) / sizeof((a)[0]), (void)0))
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
@@ -83,7 +96,7 @@ void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
void ttyhangup(void);
-int ttynew(char *, char *, char *, char **);
+int ttynew(const char *, char *, const char *, char **);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
@@ -102,7 +115,7 @@ size_t utf8encode(Rune, char *);
void *xmalloc(size_t);
void *xrealloc(void *, size_t);
-char *xstrdup(char *);
+char *xstrdup(const char *);
/* config.h globals */
extern char *utmp;