ifU(max<0)FATAL("max too large, must be <= isize::max (%lu)",SIZE_MAX>>1);
elseif(!max)return0;
while(wr<0)wr=max+wr;
wr=wr>=max?wr%max:wr;
debug_assert(wr>0);
returnwr;
}
// Create a cstring (nul-terminated) from `from`. This string is statically allocated and should not be modified.
// `sl` - Max size of `from` buffer. If 0, then just free the allocated buffer and return empty string;
// `from` - Non-nul-terminated string buffer to copy from.
// `len` - A pointer to a wrappable index for `from`. If `len` is negative, then offset from `sl`, if it's positive, offset from 0; if it's NULL, use `sl` itself. It is wrapped around `sl` in the case that the computed offset is >= sl.
//
// # Notes
// Don't `free()` this returned pointer, this function handles that on call and on program exit.