| 1877 | */ |
| 1878 | |
| 1879 | int /* O - Number of bytes written */ |
| 1880 | httpPrintf(http_t *http, /* I - HTTP connection */ |
| 1881 | const char *format, /* I - printf-style format string */ |
| 1882 | ...) /* I - Additional args as needed */ |
| 1883 | { |
| 1884 | ssize_t bytes; /* Number of bytes to write */ |
| 1885 | char buf[65536]; /* Buffer for formatted string */ |
| 1886 | va_list ap; /* Variable argument pointer */ |
| 1887 | |
| 1888 | |
| 1889 | DEBUG_printf(("2httpPrintf(http=%p, format=\"%s\", ...)", (void *)http, format)); |
| 1890 | |
| 1891 | va_start(ap, format); |
| 1892 | bytes = vsnprintf(buf, sizeof(buf), format, ap); |
| 1893 | va_end(ap); |
| 1894 | |
| 1895 | DEBUG_printf(("3httpPrintf: (" CUPS_LLFMT " bytes) %s", CUPS_LLCAST bytes, buf)); |
| 1896 | |
| 1897 | if (bytes > (ssize_t)(sizeof(buf) - 1)) |
| 1898 | { |
| 1899 | http->error = ENOMEM; |
| 1900 | return (-1); |
| 1901 | } |
| 1902 | else if (http->data_encoding == HTTP_ENCODING_FIELDS) |
| 1903 | return ((int)httpWrite2(http, buf, (size_t)bytes)); |
| 1904 | else |
| 1905 | { |
| 1906 | if (http->wused) |
| 1907 | { |
| 1908 | DEBUG_puts("4httpPrintf: flushing existing data..."); |
| 1909 | |
| 1910 | if (httpFlushWrite(http) < 0) |
| 1911 | return (-1); |
| 1912 | } |
| 1913 | |
| 1914 | return ((int)http_write(http, buf, (size_t)bytes)); |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | |
| 1919 | /* |
no test coverage detected