This is the rsync debugging function. Call it with FINFO, FERROR_*, * FWARNING, FLOG, or FCLIENT. */
| 404 | /* This is the rsync debugging function. Call it with FINFO, FERROR_*, |
| 405 | * FWARNING, FLOG, or FCLIENT. */ |
| 406 | void rprintf(enum logcode code, const char *format, ...) |
| 407 | { |
| 408 | va_list ap; |
| 409 | char buf[BIGPATHBUFLEN]; |
| 410 | size_t len; |
| 411 | |
| 412 | va_start(ap, format); |
| 413 | len = vsnprintf(buf, sizeof buf, format, ap); |
| 414 | va_end(ap); |
| 415 | |
| 416 | /* Deal with buffer overruns. Instead of panicking, just |
| 417 | * truncate the resulting string. (Note that configure ensures |
| 418 | * that we have a vsnprintf() that doesn't ever return -1.) */ |
| 419 | if (len > sizeof buf - 1) { |
| 420 | static const char ellipsis[] = "[...]"; |
| 421 | |
| 422 | /* Reset length, and zero-terminate the end of our buffer */ |
| 423 | len = sizeof buf - 1; |
| 424 | buf[len] = '\0'; |
| 425 | |
| 426 | /* Copy the ellipsis to the end of the string, but give |
| 427 | * us one extra character: |
| 428 | * |
| 429 | * v--- null byte at buf[sizeof buf - 1] |
| 430 | * abcdefghij0 |
| 431 | * -> abcd[...]00 <-- now two null bytes at end |
| 432 | * |
| 433 | * If the input format string has a trailing newline, |
| 434 | * we copy it into that extra null; if it doesn't, well, |
| 435 | * all we lose is one byte. */ |
| 436 | memcpy(buf+len-sizeof ellipsis, ellipsis, sizeof ellipsis); |
| 437 | if (format[strlen(format)-1] == '\n') { |
| 438 | buf[len-1] = '\n'; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | rwrite(code, buf, len, 0); |
| 443 | } |
| 444 | |
| 445 | /* This is like rprintf, but it also tries to print some |
| 446 | * representation of the error code. Normally errcode = errno. |
no test coverage detected