+ iov[0].iov_base = (void*)prefixes[CROP_LOGLEVEL(loglevel)] + (tty - 1 ? 4 : 0);
+ iov[0].iov_len = strlen(iov[0].iov_base);
+
+ /* " " */
+ iov[1].iov_base = (void*)&chars[2];
+ iov[1].iov_len = 2;
+
+ n = 2;
+ if (fmt) {
+ iov[n].iov_base = buffer;
+ errno = saverr;
+ rc = vsnprintf(buffer, sizeof buffer, fmt, args);
+ if (rc < 0)
+ rc = 0;
+ else if ((size_t)rc > sizeof buffer) {
+ /* if too long, ellipsis the end with ... */
+ rc = (int)sizeof buffer;
+ buffer[rc - 1] = buffer[rc - 2] = buffer[rc - 3] = '.';
+ }
+ iov[n++].iov_len = (size_t)rc;
+ }
+ if (file && (!fmt || tty == 1 || loglevel <= Log_Level_Warning)) {
+
+ if (colorize)
+ {
+ iov[n].iov_base = (void*)COLOR_FILE;
+ iov[n++].iov_len = strlen(COLOR_FILE);
+ }
+
+ /* "[" (!fmt) or " [" (fmt) */
+ iov[n].iov_base = (void*)&chars[3 + !fmt];
+ iov[n++].iov_len = 2 - !fmt;
+ /* file */
+ iov[n].iov_base = (void*)file;
+ iov[n++].iov_len = strlen(file);
+ /* ":" */
+ iov[n].iov_base = (void*)&chars[2];
+ iov[n++].iov_len = 1;
+ if (line) {
+ /* line number */
+ iov[n].iov_base = lino;
+ iov[n++].iov_len = snprintf(lino, sizeof lino, "%d", line);
+ } else {
+ /* "?" */
+ iov[n].iov_base = (void*)&chars[1];
+ iov[n++].iov_len = 1;
+ }
+ /* "," */
+ iov[n].iov_base = (void*)&chars[5];
+ iov[n++].iov_len = 1;
+ if (function) {
+ /* function name */
+ iov[n].iov_base = (void*)function;
+ iov[n++].iov_len = strlen(function);
+ } else {
+ /* "?" */
+ iov[n].iov_base = (void*)&chars[1];
+ iov[n++].iov_len = 1;
+ }
+ iov[n].iov_base = (void*)&chars[6];
+ iov[n++].iov_len = 1;
+
+ if (colorize)
+ {
+ iov[n].iov_base = (void*)COLOR_DEFAULT;
+ iov[n++].iov_len = strlen(COLOR_DEFAULT);
+ }
+ }
+ if (n == 2) {
+ /* "?" */
+ iov[n].iov_base = (void*)&chars[1];
+ iov[n++].iov_len = 1;
+ }
+ /* "\n" */
+ iov[n].iov_base = (void*)&chars[0];
+ iov[n++].iov_len = 1;
+
+ /* emit the message */
+ pthread_mutex_lock(&mutex);
+ writev(STDERR_FILENO, iov, n);
+ pthread_mutex_unlock(&mutex);
+
+ /* restore errno */
+ errno = saverr;