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

Function cupsFileWrite

cups/file.c:2147–2203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2145 */
2146
2147ssize_t /* O - Number of bytes written or -1 on error */
2148cupsFileWrite(cups_file_t *fp, /* I - CUPS file */
2149 const char *buf, /* I - Buffer */
2150 size_t bytes) /* I - Number of bytes to write */
2151{
2152 /*
2153 * Range check input...
2154 */
2155
2156 DEBUG_printf(("2cupsFileWrite(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST bytes));
2157
2158 if (!fp || !buf || (fp->mode != 'w' && fp->mode != 's'))
2159 return (-1);
2160
2161 if (bytes == 0)
2162 return (0);
2163
2164 /*
2165 * Write the buffer...
2166 */
2167
2168 if (fp->mode == 's')
2169 {
2170 if (cups_write(fp, buf, bytes) < 0)
2171 return (-1);
2172
2173 fp->pos += (off_t)bytes;
2174
2175 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
2176
2177 return ((ssize_t)bytes);
2178 }
2179
2180 if ((fp->ptr + bytes) > fp->end)
2181 if (cupsFileFlush(fp))
2182 return (-1);
2183
2184 fp->pos += (off_t)bytes;
2185
2186 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
2187
2188 if (bytes > sizeof(fp->buf))
2189 {
2190#ifdef HAVE_LIBZ
2191 if (fp->compressed)
2192 return (cups_compress(fp, buf, bytes));
2193 else
2194#endif /* HAVE_LIBZ */
2195 return (cups_write(fp, buf, bytes));
2196 }
2197 else
2198 {
2199 memcpy(fp->ptr, buf, bytes);
2200 fp->ptr += bytes;
2201 return ((ssize_t)bytes);
2202 }
2203}
2204

Callers 15

list_ppdsFunction · 0.85
install_cupsd_confFunction · 0.85
copy_fileFunction · 0.85
write_xml_stringFunction · 0.85
put_utf16Function · 0.85
backend_init_suppliesFunction · 0.85
do_config_serverFunction · 0.85
copy_non_dscFunction · 0.85
doc_writeFunction · 0.85
mainFunction · 0.85
random_testsFunction · 0.85

Calls 3

cups_writeFunction · 0.85
cupsFileFlushFunction · 0.85
cups_compressFunction · 0.85

Tested by 2

random_testsFunction · 0.68
read_write_testsFunction · 0.68