+#define ARRAY_LEN(x) (sizeof((x)) / sizeof((x)[0]))
+
+#define SAFE_STRNCPY(dest, src, n) do { \
+ strncpy((dest), (src), (n)); \
+ if ((n) > 0) \
+ (dest)[(n)-1] = '\0'; \
+ } while (0)
+
+#define SAFE_STRNCPY_SIZEOF(dest,src) \
+ SAFE_STRNCPY((dest), (src), sizeof((dest)))
+
+/* Stolen from <glib.h>: */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
+# define G_GNUC_PRINTF( format_idx, arg_idx ) \
+ __attribute__((format (printf, format_idx, arg_idx)))
+#else /* !__GNUC__ */
+# define G_GNUC_PRINTF( format_idx, arg_idx )
+#endif /* !__GNUC__ */
+
+#define GNOKII_MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define GNOKII_MIN(a, b) (((a) < (b)) ? (a) : (b))
+