extern int _stdsprintf(char* s, const char* fmt, ...) { va_list args; int v; va_start(args, fmt); v = s ? sfvsprintf(s, SF_BUFSIZE, fmt, args) : -1; va_end(args); return v; }
static void error(int level, char* fmt, ...) { DWORD err = GetLastError(); char* cur; char* end; char* s; int n; char buf[512]; va_list ap; va_start(ap, fmt); cur = buf; end = cur + sizeof(buf) - 1; cur += sfvsprintf(cur, end - cur, fmt, ap); va_end(ap); logerr(LOG_SYSTEM+level, "%s", buf); if (!quiet) { if ((level & LOG_SYSTEM) && err && (int)(end - cur) > 32) { cur += sfsprintf(cur, end - cur, "\r\n[%lu:", err); if (!(n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, 0, err, 0, cur, (int)(end - cur), 0))) n = sfsprintf(cur, end - cur, "Unknown error code %d.\n", err); if (n >= (int)(end - cur)) cur[n-1] = 0; if (s = strchr(cur, '\n')) n = (int)(s - cur); cur += n; if (*(cur-1) == '\r') cur--; if (*(cur-1) == '.') cur--; if (cur < end) *cur++ = ']'; } *cur = 0; MessageBox(0, buf, "UWIN Setuid Service", 0x00200000L|0x00040000L|MB_OK|MB_ICONSTOP); } }