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

Function cupsFilePutConf

cups/file.c:1513–1612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1511 */
1512
1513ssize_t /* O - Number of bytes written or -1 on error */
1514cupsFilePutConf(cups_file_t *fp, /* I - CUPS file */
1515 const char *directive, /* I - Directive */
1516 const char *value) /* I - Value */
1517{
1518 ssize_t bytes, /* Number of bytes written */
1519 temp; /* Temporary byte count */
1520
1521
1522 if (!fp || !directive || !*directive)
1523 return (-1);
1524
1525 if ((bytes = cupsFilePuts(fp, directive)) < 0)
1526 return (-1);
1527
1528 if (value && *value)
1529 {
1530 const char *start, // Start of current fragment
1531 *ptr; // Pointer into value
1532
1533 if (cupsFilePutChar(fp, ' ') < 0)
1534 return (-1);
1535 bytes ++;
1536
1537 for (start = ptr = value; *ptr; ptr ++)
1538 {
1539 if (strchr("#\\\n\r", *ptr) != NULL)
1540 {
1541 /*
1542 * Character that needs to be escaped...
1543 */
1544
1545 if (ptr > start)
1546 {
1547 /*
1548 * Write unescaped portion...
1549 */
1550
1551 if ((temp = cupsFileWrite(fp, start, (size_t)(ptr - start))) < 0)
1552 return (-1);
1553
1554 bytes += temp;
1555 }
1556
1557 start = ptr + 1;
1558
1559 if (*ptr == '\\')
1560 {
1561 /*
1562 * "\" (for escaping)
1563 */
1564
1565 if (cupsFilePuts(fp, "\\\\") < 0)
1566 return (-1);
1567 }
1568 else if (*ptr == '#')
1569 {
1570 /*

Callers 6

save_auth_infoFunction · 0.85
cupsdSaveAllJobsFunction · 0.85
cupsdSaveAllClassesFunction · 0.85
cupsdSaveAllPrintersFunction · 0.85
_ppdCacheWriteFileFunction · 0.85
read_write_testsFunction · 0.85

Calls 3

cupsFilePutsFunction · 0.85
cupsFilePutCharFunction · 0.85
cupsFileWriteFunction · 0.85

Tested by 1

read_write_testsFunction · 0.68