summaryrefslogtreecommitdiff
path: root/cups/file.c
diff options
context:
space:
mode:
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2008-10-08 22:50:16 +0000
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2008-10-08 22:50:16 +0000
commit58dc193312e27d25c0394e4fcb7a6eed7301b1ec (patch)
treef36e45a693b16fbf643e8c168180f02343b38431 /cups/file.c
parentf2245c695c43045dbdc825289307099c9c4559a2 (diff)
downloadcups-58dc193312e27d25c0394e4fcb7a6eed7301b1ec.tar.gz
Merge changes from CUPS 1.4svn-r8033.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@1003 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/file.c')
-rw-r--r--cups/file.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/cups/file.c b/cups/file.c
index 815e1d3c5..bbaac6fe0 100644
--- a/cups/file.c
+++ b/cups/file.c
@@ -1254,6 +1254,67 @@ cupsFilePutChar(cups_file_t *fp, /* I - CUPS file */
/*
+ * 'cupsFilePutConf()' - Write a configuration line.
+ *
+ * This function handles any comment escaping of the value.
+ *
+ * @since CUPS 1.4@
+ */
+
+ssize_t /* O - Number of bytes written or -1 on error */
+cupsFilePutConf(cups_file_t *fp, /* I - CUPS file */
+ const char *directive, /* I - Directive */
+ const char *value) /* I - Value */
+{
+ ssize_t bytes, /* Number of bytes written */
+ temp; /* Temporary byte count */
+ const char *ptr; /* Pointer into value */
+
+
+ if (!fp || !directive || !*directive)
+ return (-1);
+
+ if ((bytes = cupsFilePuts(fp, directive)) < 0)
+ return (-1);
+
+ if (cupsFilePutChar(fp, ' ') < 0)
+ return (-1);
+ bytes ++;
+
+ if (value && *value)
+ {
+ if ((ptr = strchr(value, '#')) != NULL)
+ {
+ /*
+ * Need to quote the first # in the info string...
+ */
+
+ if ((temp = cupsFileWrite(fp, value, ptr - value)) < 0)
+ return (-1);
+ bytes += temp;
+
+ if (cupsFilePutChar(fp, '\\') < 0)
+ return (-1);
+ bytes ++;
+
+ if ((temp = cupsFilePuts(fp, ptr)) < 0)
+ return (-1);
+ bytes += temp;
+ }
+ else if ((temp = cupsFilePuts(fp, value)) < 0)
+ return (-1);
+ else
+ bytes += temp;
+ }
+
+ if (cupsFilePutChar(fp, '\n') < 0)
+ return (-1);
+ else
+ return (bytes + 1);
+}
+
+
+/*
* 'cupsFilePuts()' - Write a string.
*
* Like the @code fputs@ function, no newline is appended to the string.