MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsFilePrintf

Function cupsFilePrintf

cups/file.c:1358–1450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1356 */
1357
1358int /* O - Number of bytes written or -1 on error */
1359cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */
1360 const char *format, /* I - Printf-style format string */
1361 ...) /* I - Additional args as necessary */
1362{
1363 va_list ap; /* Argument list */
1364 ssize_t bytes; /* Formatted size */
1365
1366
1367 DEBUG_printf(("2cupsFilePrintf(fp=%p, format=\"%s\", ...)", (void *)fp, format));
1368
1369 if (!fp || !format || (fp->mode != 'w' && fp->mode != 's'))
1370 return (-1);
1371
1372 if (!fp->printf_buffer)
1373 {
1374 /*
1375 * Start with a 1k printf buffer...
1376 */
1377
1378 if ((fp->printf_buffer = malloc(1024)) == NULL)
1379 return (-1);
1380
1381 fp->printf_size = 1024;
1382 }
1383
1384 va_start(ap, format);
1385 bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap);
1386 va_end(ap);
1387
1388 if (bytes >= (ssize_t)fp->printf_size)
1389 {
1390 /*
1391 * Expand the printf buffer...
1392 */
1393
1394 char *temp; /* Temporary buffer pointer */
1395
1396
1397 if (bytes > 65535)
1398 return (-1);
1399
1400 if ((temp = realloc(fp->printf_buffer, (size_t)(bytes + 1))) == NULL)
1401 return (-1);
1402
1403 fp->printf_buffer = temp;
1404 fp->printf_size = (size_t)(bytes + 1);
1405
1406 va_start(ap, format);
1407 bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap);
1408 va_end(ap);
1409 }
1410
1411 if (fp->mode == 's')
1412 {
1413 if (cups_write(fp, fp->printf_buffer, (size_t)bytes) < 0)
1414 return (-1);
1415

Callers 15

mainFunction · 0.85
do_monitor_printer_stateFunction · 0.85
do_testFunction · 0.85
pause_messageFunction · 0.85
print_attrFunction · 0.85
print_ippserver_attrFunction · 0.85
print_json_attrFunction · 0.85
print_json_stringFunction · 0.85
print_lineFunction · 0.85
print_xml_headerFunction · 0.85
print_xml_stringFunction · 0.85
token_cbFunction · 0.85

Calls 3

cups_writeFunction · 0.85
cupsFileFlushFunction · 0.85
cups_compressFunction · 0.85

Tested by 1

read_write_testsFunction · 0.68