+/*
+ * Sets the library error to code, with a printf-style error string.
+ */
+void cdecl__err(unsigned code, const char *fmt, ...)
+{
+ struct err_state *state;
+ int rc, try = 0;
+ va_list ap;
+
+ state = get_err_state();
+ if (!state)
+ return;
+
+retry:
+ va_start(ap, fmt);
+ rc = vsnprintf(state->str, state->nstr, fmt, ap);
+ va_end(ap);
+
+ if (rc > 0 && rc >= state->nstr) {
+ assert(try++ == 0 && rc < SIZE_MAX / 4);
+ state = alloc_err_state(state, (size_t)(rc+1u) * 3 / 2);
+ if (!state)
+ return;
+
+ goto retry;
+ }
+
+ state->err.str = state->str;
+ state->err.code = code;