@ -12,11 +12,11 @@
# define DFLAGSET(f, flagname) FLAGSET(f, DISPF_SHOW_ ## flagname)
# define CMP(x,cmp,y) ( (x) cmp (y) ? (x) : (y) )
# define CMP x (x,cmp,y) ({ let _x = (x); let _y = (y); CMP(_x, cmp, _y); })
# define CMP v (x,cmp,y) ({ let _x = (x); let _y = (y); CMP(_x, cmp, _y); })
# define MIN(x, y) CMP((x), <, (y))
# define MIN x(x, y) CMPx ((x), <, (y))
# define MIN v(x, y) CMPv ((x), <, (y))
# define MAX(x, y) CMP((x), >, (y))
# define MAX x(x, y) CMPx ((x), >, (y))
# define MAX v(x, y) CMPv ((x), >, (y))
// Returns number of bytes written to `dest`. Otherwise same as `strncpy()`.
static usize strncpy_n ( char * pOUT dest , const char * restrict src , usize n )
@ -42,7 +42,7 @@ static usize s_strncpy_n(usize sn, usize dn; char dest[static pOUT dn], usize dn
// Will not write past `dn` bytes of `dest`, will not read past `sn` bytes of `src`. Otherwise, same as `strncat_n()`.
static inline usize s_strncat_n ( usize sn , usize dn ; char dest [ static pOUT dn ] , usize dn , const char src [ static restrict sn ] , usize sn )
{
usize dl = MIN x ( strlen ( dest ) , dn ) ;
usize dl = MIN v ( strlen ( dest ) , dn ) ;
return s_strncpy_n ( dest + dl , dn - dl , src , sn ) ;
}
@ -75,10 +75,10 @@ static usize _display_get_fmt_n(dispflags_t flags, bool matched, usize _n, char
//TODO: Fix this... It isn't working...
# define ADDSTR(s) do { \
debug_assert ( ( s ) ) ; \
w = MIN x ( s_strncat_n ( str , n , ( s ) , n ) , n ) ; \
w = MIN v ( s_strncat_n ( str , n , ( s ) , n ) , n ) ; \
/* Remove written from `n` */ \
n - = w ; \
/* Check if we have written into the limit (if so, w will be equal to n above, since w is high-bounded to n by `MIN x ()` above. So if n is 0, we have hit the limit. */ \
/* Check if we have written into the limit (if so, w will be equal to n above, since w is high-bounded to n by `MIN v ()` above. So if n is 0, we have hit the limit. */ \
ifU ( ! n ) { \
/*XXX: Should this be `str[w-1]?` If this assert fails then yes it should. */ \
debug_assert ( w < _n ) ; \