]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/file.c
bbaac6fe0a1f9245fbca5dda5d186ca30e136426
2 * "$Id: file.c 7672 2008-06-18 22:03:02Z mike $"
4 * File functions for the Common UNIX Printing System (CUPS).
6 * Since stdio files max out at 256 files on many systems, we have to
7 * write similar functions without this limit. At the same time, using
8 * our own file functions allows us to provide transparent support of
9 * gzip'd print files, PPD files, etc.
11 * Copyright 2007-2008 by Apple Inc.
12 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
14 * These coded instructions, statements, and computer programs are the
15 * property of Apple Inc. and are protected by Federal copyright
16 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
17 * which should have been included with this file. If this file is
18 * file is missing or damaged, see the license at "http://www.cups.org/".
22 * cupsFileClose() - Close a CUPS file.
23 * cupsFileCompression() - Return whether a file is compressed.
24 * cupsFileEOF() - Return the end-of-file status.
25 * cupsFileFind() - Find a file using the specified path.
26 * cupsFileFlush() - Flush pending output.
27 * cupsFileGetChar() - Get a single character from a file.
28 * cupsFileGetConf() - Get a line from a configuration file...
29 * cupsFileGetLine() - Get a CR and/or LF-terminated line that may contain
31 * cupsFileGets() - Get a CR and/or LF-terminated line.
32 * cupsFileLock() - Temporarily lock access to a file.
33 * cupsFileNumber() - Return the file descriptor associated with a CUPS
35 * cupsFileOpen() - Open a CUPS file.
36 * cupsFileOpenFd() - Open a CUPS file using a file descriptor.
37 * cupsFilePeekChar() - Peek at the next character from a file.
38 * cupsFilePrintf() - Write a formatted string.
39 * cupsFilePutChar() - Write a character.
40 * cupsFilePuts() - Write a string.
41 * cupsFileRead() - Read from a file.
42 * cupsFileRewind() - Set the current file position to the beginning of
44 * cupsFileSeek() - Seek in a file.
45 * cupsFileStderr() - Return a CUPS file associated with stderr.
46 * cupsFileStdin() - Return a CUPS file associated with stdin.
47 * cupsFileStdout() - Return a CUPS file associated with stdout.
48 * cupsFileTell() - Return the current file position.
49 * cupsFileUnlock() - Unlock access to a file.
50 * cupsFileWrite() - Write to a file.
51 * cups_compress() - Compress a buffer of data...
52 * cups_fill() - Fill the input buffer...
53 * cups_read() - Read from a file descriptor.
54 * cups_write() - Write to a file descriptor.
58 * Include necessary headers...
65 #include <sys/types.h>
67 #include "http-private.h"
73 #endif /* HAVE_LIBZ */
76 # include <sys/locking.h>
81 * Some operating systems support large files via open flag O_LARGEFILE...
85 # define O_LARGEFILE 0
86 #endif /* !O_LARGEFILE */
90 * Some operating systems don't define O_BINARY, which is used by Microsoft
91 * and IBM to flag binary files...
96 #endif /* !O_BINARY */
100 * Types and structures...
103 struct _cups_file_s
/**** CUPS file structure... ****/
106 int fd
; /* File descriptor */
107 char mode
, /* Mode ('r' or 'w') */
108 compressed
, /* Compression used? */
109 is_stdio
, /* stdin/out/err? */
110 eof
, /* End of file? */
111 buf
[4096], /* Buffer */
112 *ptr
, /* Pointer into buffer */
113 *end
; /* End of buffer data */
114 off_t pos
, /* Position in file */
115 bufpos
; /* File position for start of buffer */
118 z_stream stream
; /* (De)compression stream */
119 Bytef cbuf
[4096]; /* (De)compression buffer */
120 uLong crc
; /* (De)compression CRC */
121 #endif /* HAVE_LIBZ */
123 char *printf_buffer
; /* cupsFilePrintf buffer */
124 size_t printf_size
; /* Size of cupsFilePrintf buffer */
133 static ssize_t
cups_compress(cups_file_t
*fp
, const char *buf
, size_t bytes
);
134 #endif /* HAVE_LIBZ */
135 static ssize_t
cups_fill(cups_file_t
*fp
);
136 static ssize_t
cups_read(cups_file_t
*fp
, char *buf
, size_t bytes
);
137 static ssize_t
cups_write(cups_file_t
*fp
, const char *buf
, size_t bytes
);
141 * 'cupsFileClose()' - Close a CUPS file.
146 int /* O - 0 on success, -1 on error */
147 cupsFileClose(cups_file_t
*fp
) /* I - CUPS file */
149 int fd
; /* File descriptor */
150 char mode
; /* Open mode */
151 int status
; /* Return status */
152 int is_stdio
; /* Is a stdio file? */
155 DEBUG_printf(("cupsFileClose(fp=%p)\n", fp
));
165 * Flush pending write data...
169 status
= cupsFileFlush(fp
);
174 if (fp
->compressed
&& status
>= 0)
179 * Free decompression data...
182 inflateEnd(&fp
->stream
);
187 * Flush any remaining compressed data...
190 unsigned char trailer
[8]; /* Trailer CRC and length */
191 int done
; /* Done writing... */
194 fp
->stream
.avail_in
= 0;
198 if (fp
->stream
.next_out
> fp
->cbuf
)
200 if (cups_write(fp
, (char *)fp
->cbuf
,
201 fp
->stream
.next_out
- fp
->cbuf
) < 0)
204 fp
->stream
.next_out
= fp
->cbuf
;
205 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
208 if (done
|| status
< 0)
211 done
= deflate(&fp
->stream
, Z_FINISH
) == Z_STREAM_END
&&
212 fp
->stream
.next_out
== fp
->cbuf
;
216 * Write the CRC and length...
219 trailer
[0] = fp
->crc
;
220 trailer
[1] = fp
->crc
>> 8;
221 trailer
[2] = fp
->crc
>> 16;
222 trailer
[3] = fp
->crc
>> 24;
223 trailer
[4] = fp
->pos
;
224 trailer
[5] = fp
->pos
>> 8;
225 trailer
[6] = fp
->pos
>> 16;
226 trailer
[7] = fp
->pos
>> 24;
228 if (cups_write(fp
, (char *)trailer
, 8) < 0)
232 * Free all memory used by the compression stream...
235 deflateEnd(&(fp
->stream
));
238 #endif /* HAVE_LIBZ */
241 * Save the file descriptor we used and free memory...
246 is_stdio
= fp
->is_stdio
;
248 if (fp
->printf_buffer
)
249 free(fp
->printf_buffer
);
254 * Close the file, returning the close status...
259 if (closesocket(fd
) < 0)
273 * 'cupsFileCompression()' - Return whether a file is compressed.
278 int /* O - @code CUPS_FILE_NONE@ or @code CUPS_FILE_GZIP@ */
279 cupsFileCompression(cups_file_t
*fp
) /* I - CUPS file */
281 return (fp
? fp
->compressed
: CUPS_FILE_NONE
);
286 * 'cupsFileEOF()' - Return the end-of-file status.
291 int /* O - 1 on end of file, 0 otherwise */
292 cupsFileEOF(cups_file_t
*fp
) /* I - CUPS file */
294 return (fp
? fp
->eof
: 1);
299 * 'cupsFileFind()' - Find a file using the specified path.
301 * This function allows the paths in the path string to be separated by
302 * colons (UNIX standard) or semicolons (Windows standard) and stores the
303 * result in the buffer supplied. If the file cannot be found in any of
304 * the supplied paths, @code NULL@ is returned. A @code NULL@ path only
305 * matches the current directory.
310 const char * /* O - Full path to file or @code NULL@ if not found */
311 cupsFileFind(const char *filename
, /* I - File to find */
312 const char *path
, /* I - Colon/semicolon-separated path */
313 int executable
, /* I - 1 = executable files, 0 = any file/dir */
314 char *buffer
, /* I - Filename buffer */
315 int bufsize
) /* I - Size of filename buffer */
317 char *bufptr
, /* Current position in buffer */
318 *bufend
; /* End of buffer */
322 * Range check input...
325 if (!filename
|| !buffer
|| bufsize
< 2)
331 * No path, so check current directory...
334 if (!access(filename
, 0))
336 strlcpy(buffer
, filename
, bufsize
);
344 * Now check each path and return the first match...
347 bufend
= buffer
+ bufsize
- 1;
353 if (*path
== ';' || (*path
== ':' && ((bufptr
- buffer
) > 1 || !isalpha(buffer
[0] & 255))))
355 if (*path
== ';' || *path
== ':')
358 if (bufptr
> buffer
&& bufptr
[-1] != '/' && bufptr
< bufend
)
361 strlcpy(bufptr
, filename
, bufend
- bufptr
);
364 if (!access(buffer
, 0))
366 if (!access(buffer
, executable
? X_OK
: 0))
369 DEBUG_printf(("cupsFileFind: Returning \"%s\"\n", buffer
));
375 else if (bufptr
< bufend
)
382 * Check the last path...
385 if (bufptr
> buffer
&& bufptr
[-1] != '/' && bufptr
< bufend
)
388 strlcpy(bufptr
, filename
, bufend
- bufptr
);
390 if (!access(buffer
, 0))
392 DEBUG_printf(("cupsFileFind: Returning \"%s\"\n", buffer
));
397 DEBUG_puts("cupsFileFind: Returning NULL");
404 * 'cupsFileFlush()' - Flush pending output.
409 int /* O - 0 on success, -1 on error */
410 cupsFileFlush(cups_file_t
*fp
) /* I - CUPS file */
412 ssize_t bytes
; /* Bytes to write */
415 DEBUG_printf(("cupsFileFlush(fp=%p)\n", fp
));
418 * Range check input...
421 if (!fp
|| fp
->mode
!= 'w')
423 DEBUG_puts("cupsFileFlush: Attempt to flush a read-only file...");
427 bytes
= (ssize_t
)(fp
->ptr
- fp
->buf
);
429 DEBUG_printf(("cupsFileFlush: Flushing " CUPS_LLFMT
" bytes...\n",
436 bytes
= cups_compress(fp
, fp
->buf
, bytes
);
438 #endif /* HAVE_LIBZ */
439 bytes
= cups_write(fp
, fp
->buf
, bytes
);
452 * 'cupsFileGetChar()' - Get a single character from a file.
457 int /* O - Character or -1 on end of file */
458 cupsFileGetChar(cups_file_t
*fp
) /* I - CUPS file */
461 * Range check input...
464 DEBUG_printf(("cupsFileGetChar(fp=%p)\n", fp
));
466 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's'))
468 DEBUG_puts("cupsFileGetChar: Bad arguments!");
473 * If the input buffer is empty, try to read more data...
476 if (fp
->ptr
>= fp
->end
)
477 if (cups_fill(fp
) < 0)
479 DEBUG_puts("cupsFileGetChar: Unable to fill buffer!");
484 * Return the next character in the buffer...
487 DEBUG_printf(("cupsFileGetChar: Returning %d...\n", *(fp
->ptr
) & 255));
491 DEBUG_printf(("cupsFileGetChar: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
493 return (*(fp
->ptr
)++ & 255);
498 * 'cupsFileGetConf()' - Get a line from a configuration file...
503 char * /* O - Line read or @code NULL@ on end of file or error */
504 cupsFileGetConf(cups_file_t
*fp
, /* I - CUPS file */
505 char *buf
, /* O - String buffer */
506 size_t buflen
, /* I - Size of string buffer */
507 char **value
, /* O - Pointer to value */
508 int *linenum
) /* IO - Current line number */
510 char *ptr
; /* Pointer into line */
514 * Range check input...
517 DEBUG_printf(("cupsFileGetConf(fp=%p, buf=%p, buflen=" CUPS_LLFMT
518 ", value=%p, linenum=%p)\n", fp
, buf
, CUPS_LLCAST buflen
,
521 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') ||
522 !buf
|| buflen
< 2 || !value
)
531 * Read the next non-comment line...
536 while (cupsFileGets(fp
, buf
, buflen
))
541 * Strip any comments...
544 if ((ptr
= strchr(buf
, '#')) != NULL
)
546 if (ptr
> buf
&& ptr
[-1] == '\\')
549 _cups_strcpy(ptr
- 1, ptr
);
553 // Strip the comment and any trailing whitespace...
556 if (!isspace(ptr
[-1] & 255))
567 * Strip leading whitespace...
570 for (ptr
= buf
; isspace(*ptr
& 255); ptr
++);
573 _cups_strcpy(buf
, ptr
);
576 * See if there is anything left...
582 * Yes, grab any value and return...
585 for (ptr
= buf
; *ptr
; ptr
++)
586 if (isspace(*ptr
& 255))
592 * Have a value, skip any other spaces...
595 while (isspace(*ptr
& 255))
602 * Strip trailing whitespace and > for lines that begin with <...
605 ptr
+= strlen(ptr
) - 1;
607 if (buf
[0] == '<' && *ptr
== '>')
609 else if (buf
[0] == '<' && *ptr
!= '>')
619 while (ptr
> *value
&& isspace(*ptr
& 255))
636 * 'cupsFileGetLine()' - Get a CR and/or LF-terminated line that may
637 * contain binary data.
639 * This function differs from @link cupsFileGets@ in that the trailing CR
640 * and LF are preserved, as is any binary data on the line. The buffer is
641 * nul-terminated, however you should use the returned length to determine
642 * the number of bytes on the line.
647 size_t /* O - Number of bytes on line or 0 on end of file */
648 cupsFileGetLine(cups_file_t
*fp
, /* I - File to read from */
649 char *buf
, /* I - Buffer */
650 size_t buflen
) /* I - Size of buffer */
652 int ch
; /* Character from file */
653 char *ptr
, /* Current position in line buffer */
654 *end
; /* End of line buffer */
658 * Range check input...
661 DEBUG_printf(("cupsFileGetLine(fp=%p, buf=%p, buflen=" CUPS_LLFMT
")\n",
662 fp
, buf
, CUPS_LLCAST buflen
));
664 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') || !buf
|| buflen
< 3)
668 * Now loop until we have a valid line...
671 for (ptr
= buf
, end
= buf
+ buflen
- 2; ptr
< end
;)
673 if (fp
->ptr
>= fp
->end
)
674 if (cups_fill(fp
) <= 0)
677 *ptr
++ = ch
= *(fp
->ptr
)++;
686 if (fp
->ptr
>= fp
->end
)
687 if (cups_fill(fp
) <= 0)
690 if (*(fp
->ptr
) == '\n')
692 *ptr
++ = *(fp
->ptr
)++;
701 * Line feed ends a line...
710 DEBUG_printf(("cupsFileGetLine: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
717 * 'cupsFileGets()' - Get a CR and/or LF-terminated line.
722 char * /* O - Line read or @code NULL@ on end of file or error */
723 cupsFileGets(cups_file_t
*fp
, /* I - CUPS file */
724 char *buf
, /* O - String buffer */
725 size_t buflen
) /* I - Size of string buffer */
727 int ch
; /* Character from file */
728 char *ptr
, /* Current position in line buffer */
729 *end
; /* End of line buffer */
733 * Range check input...
736 DEBUG_printf(("cupsFileGets(fp=%p, buf=%p, buflen=" CUPS_LLFMT
")\n", fp
, buf
,
737 CUPS_LLCAST buflen
));
739 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') || !buf
|| buflen
< 2)
743 * Now loop until we have a valid line...
746 for (ptr
= buf
, end
= buf
+ buflen
- 1; ptr
< end
;)
748 if (fp
->ptr
>= fp
->end
)
749 if (cups_fill(fp
) <= 0)
766 if (fp
->ptr
>= fp
->end
)
767 if (cups_fill(fp
) <= 0)
770 if (*(fp
->ptr
) == '\n')
781 * Line feed ends a line...
792 DEBUG_printf(("cupsFileGets: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
799 * 'cupsFileLock()' - Temporarily lock access to a file.
804 int /* O - 0 on success, -1 on error */
805 cupsFileLock(cups_file_t
*fp
, /* I - CUPS file */
806 int block
) /* I - 1 to wait for the lock, 0 to fail right away */
812 if (!fp
|| fp
->mode
== 's')
820 return (locking(fp
->fd
, block
? _LK_LOCK
: _LK_NBLCK
, 0));
822 return (lockf(fp
->fd
, block
? F_LOCK
: F_TLOCK
, 0));
828 * 'cupsFileNumber()' - Return the file descriptor associated with a CUPS file.
833 int /* O - File descriptor */
834 cupsFileNumber(cups_file_t
*fp
) /* I - CUPS file */
844 * 'cupsFileOpen()' - Open a CUPS file.
846 * The "mode" parameter can be "r" to read, "w" to write, overwriting any
847 * existing file, "a" to append to an existing file or create a new file,
848 * or "s" to open a socket connection.
850 * When opening for writing ("w"), an optional number from 1 to 9 can be
851 * supplied which enables Flate compression of the file. Compression is
852 * not supported for the "a" (append) mode.
854 * When opening a socket connection, the filename is a string of the form
855 * "address:port" or "hostname:port". The socket will make an IPv4 or IPv6
856 * connection as needed, generally preferring IPv6 connections when there is
862 cups_file_t
* /* O - CUPS file or @code NULL@ if the file or socket cannot be opened */
863 cupsFileOpen(const char *filename
, /* I - Name of file */
864 const char *mode
) /* I - Open mode */
866 cups_file_t
*fp
; /* New CUPS file */
867 int fd
; /* File descriptor */
868 char hostname
[1024], /* Hostname */
869 *portname
; /* Port "name" (number or service) */
870 http_addrlist_t
*addrlist
; /* Host address list */
873 DEBUG_printf(("cupsFileOpen(filename=\"%s\", mode=\"%s\")\n", filename
,
877 * Range check input...
880 if (!filename
|| !mode
||
881 (*mode
!= 'r' && *mode
!= 'w' && *mode
!= 'a' && *mode
!= 's') ||
882 (*mode
== 'a' && isdigit(mode
[1] & 255)))
891 case 'a' : /* Append file */
892 fd
= open(filename
, O_RDWR
| O_CREAT
| O_APPEND
| O_LARGEFILE
| O_BINARY
, 0666);
895 case 'r' : /* Read file */
896 fd
= open(filename
, O_RDONLY
| O_LARGEFILE
| O_BINARY
, 0);
899 case 'w' : /* Write file */
900 fd
= open(filename
, O_WRONLY
| O_TRUNC
| O_CREAT
| O_LARGEFILE
| O_BINARY
, 0666);
903 case 's' : /* Read/write socket */
904 strlcpy(hostname
, filename
, sizeof(hostname
));
905 if ((portname
= strrchr(hostname
, ':')) != NULL
)
911 * Lookup the hostname and service...
914 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
918 * Connect to the server...
921 if (!httpAddrConnect(addrlist
, &fd
))
923 httpAddrFreeList(addrlist
);
927 httpAddrFreeList(addrlist
);
930 default : /* Remove bogus compiler warning... */
938 * Create the CUPS file structure...
941 if ((fp
= cupsFileOpenFd(fd
, mode
)) == NULL
)
957 * 'cupsFileOpenFd()' - Open a CUPS file using a file descriptor.
959 * The "mode" parameter can be "r" to read, "w" to write, "a" to append,
960 * or "s" to treat the file descriptor as a bidirectional socket connection.
962 * When opening for writing ("w"), an optional number from 1 to 9 can be
963 * supplied which enables Flate compression of the file. Compression is
964 * not supported for the "a" (append) mode.
969 cups_file_t
* /* O - CUPS file or @code NULL@ if the file could not be opened */
970 cupsFileOpenFd(int fd
, /* I - File descriptor */
971 const char *mode
) /* I - Open mode */
973 cups_file_t
*fp
; /* New CUPS file */
976 DEBUG_printf(("cupsFileOpenFd(fd=%d, mode=\"%s\")\n", fd
, mode
));
979 * Range check input...
982 if (fd
< 0 || !mode
||
983 (*mode
!= 'r' && *mode
!= 'w' && *mode
!= 'a' && *mode
!= 's') ||
984 (*mode
== 'a' && isdigit(mode
[1] & 255)))
991 if ((fp
= calloc(1, sizeof(cups_file_t
))) == NULL
)
1003 fp
->pos
= lseek(fd
, 0, SEEK_END
);
1008 fp
->end
= fp
->buf
+ sizeof(fp
->buf
);
1011 if (mode
[1] >= '1' && mode
[1] <= '9')
1014 * Open a compressed stream, so write the standard gzip file
1018 unsigned char header
[10]; /* gzip file header */
1019 time_t curtime
; /* Current time */
1022 curtime
= time(NULL
);
1025 header
[2] = Z_DEFLATED
;
1027 header
[4] = curtime
;
1028 header
[5] = curtime
>> 8;
1029 header
[6] = curtime
>> 16;
1030 header
[7] = curtime
>> 24;
1034 cups_write(fp
, (char *)header
, 10);
1037 * Initialize the compressor...
1040 deflateInit2(&(fp
->stream
), mode
[1] - '0', Z_DEFLATED
, -15, 8,
1041 Z_DEFAULT_STRATEGY
);
1043 fp
->stream
.next_out
= fp
->cbuf
;
1044 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
1046 fp
->crc
= crc32(0L, Z_NULL
, 0);
1048 #endif /* HAVE_LIBZ */
1059 default : /* Remove bogus compiler warning... */
1064 * Don't pass this file to child processes...
1068 fcntl(fp
->fd
, F_SETFD
, fcntl(fp
->fd
, F_GETFD
) | FD_CLOEXEC
);
1076 * 'cupsFilePeekChar()' - Peek at the next character from a file.
1081 int /* O - Character or -1 on end of file */
1082 cupsFilePeekChar(cups_file_t
*fp
) /* I - CUPS file */
1085 * Range check input...
1088 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's'))
1092 * If the input buffer is empty, try to read more data...
1095 if (fp
->ptr
>= fp
->end
)
1096 if (cups_fill(fp
) < 0)
1100 * Return the next character in the buffer...
1103 return (*(fp
->ptr
) & 255);
1108 * 'cupsFilePrintf()' - Write a formatted string.
1113 int /* O - Number of bytes written or -1 on error */
1114 cupsFilePrintf(cups_file_t
*fp
, /* I - CUPS file */
1115 const char *format
, /* I - Printf-style format string */
1116 ...) /* I - Additional args as necessary */
1118 va_list ap
; /* Argument list */
1119 ssize_t bytes
; /* Formatted size */
1122 DEBUG_printf(("cupsFilePrintf(fp=%p, format=\"%s\", ...)\n", fp
, format
));
1124 if (!fp
|| !format
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1127 if (!fp
->printf_buffer
)
1130 * Start with an 1k printf buffer...
1133 if ((fp
->printf_buffer
= malloc(1024)) == NULL
)
1136 fp
->printf_size
= 1024;
1139 va_start(ap
, format
);
1140 bytes
= vsnprintf(fp
->printf_buffer
, fp
->printf_size
, format
, ap
);
1143 if (bytes
>= fp
->printf_size
)
1146 * Expand the printf buffer...
1149 char *temp
; /* Temporary buffer pointer */
1155 if ((temp
= realloc(fp
->printf_buffer
, bytes
+ 1)) == NULL
)
1158 fp
->printf_buffer
= temp
;
1159 fp
->printf_size
= bytes
+ 1;
1161 va_start(ap
, format
);
1162 bytes
= vsnprintf(fp
->printf_buffer
, fp
->printf_size
, format
, ap
);
1166 if (fp
->mode
== 's')
1168 if (cups_write(fp
, fp
->printf_buffer
, bytes
) < 0)
1173 DEBUG_printf(("cupsFilePrintf: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1178 if ((fp
->ptr
+ bytes
) > fp
->end
)
1179 if (cupsFileFlush(fp
))
1184 DEBUG_printf(("cupsFilePrintf: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1186 if (bytes
> sizeof(fp
->buf
))
1190 return (cups_compress(fp
, fp
->printf_buffer
, bytes
));
1192 #endif /* HAVE_LIBZ */
1193 return (cups_write(fp
, fp
->printf_buffer
, bytes
));
1197 memcpy(fp
->ptr
, fp
->printf_buffer
, bytes
);
1205 * 'cupsFilePutChar()' - Write a character.
1210 int /* O - 0 on success, -1 on error */
1211 cupsFilePutChar(cups_file_t
*fp
, /* I - CUPS file */
1212 int c
) /* I - Character to write */
1215 * Range check input...
1218 if (!fp
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1221 if (fp
->mode
== 's')
1224 * Send character immediately over socket...
1227 char ch
; /* Output character */
1232 if (send(fp
->fd
, &ch
, 1, 0) < 1)
1241 if (fp
->ptr
>= fp
->end
)
1242 if (cupsFileFlush(fp
))
1250 DEBUG_printf(("cupsFilePutChar: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1257 * 'cupsFilePutConf()' - Write a configuration line.
1259 * This function handles any comment escaping of the value.
1264 ssize_t
/* O - Number of bytes written or -1 on error */
1265 cupsFilePutConf(cups_file_t
*fp
, /* I - CUPS file */
1266 const char *directive
, /* I - Directive */
1267 const char *value
) /* I - Value */
1269 ssize_t bytes
, /* Number of bytes written */
1270 temp
; /* Temporary byte count */
1271 const char *ptr
; /* Pointer into value */
1274 if (!fp
|| !directive
|| !*directive
)
1277 if ((bytes
= cupsFilePuts(fp
, directive
)) < 0)
1280 if (cupsFilePutChar(fp
, ' ') < 0)
1284 if (value
&& *value
)
1286 if ((ptr
= strchr(value
, '#')) != NULL
)
1289 * Need to quote the first # in the info string...
1292 if ((temp
= cupsFileWrite(fp
, value
, ptr
- value
)) < 0)
1296 if (cupsFilePutChar(fp
, '\\') < 0)
1300 if ((temp
= cupsFilePuts(fp
, ptr
)) < 0)
1304 else if ((temp
= cupsFilePuts(fp
, value
)) < 0)
1310 if (cupsFilePutChar(fp
, '\n') < 0)
1318 * 'cupsFilePuts()' - Write a string.
1320 * Like the @code fputs@ function, no newline is appended to the string.
1325 int /* O - Number of bytes written or -1 on error */
1326 cupsFilePuts(cups_file_t
*fp
, /* I - CUPS file */
1327 const char *s
) /* I - String to write */
1329 ssize_t bytes
; /* Bytes to write */
1333 * Range check input...
1336 if (!fp
|| !s
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1340 * Write the string...
1343 bytes
= (int)strlen(s
);
1345 if (fp
->mode
== 's')
1347 if (cups_write(fp
, s
, bytes
) < 0)
1352 DEBUG_printf(("cupsFilePuts: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1357 if ((fp
->ptr
+ bytes
) > fp
->end
)
1358 if (cupsFileFlush(fp
))
1363 DEBUG_printf(("cupsFilePuts: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1365 if (bytes
> sizeof(fp
->buf
))
1369 return (cups_compress(fp
, s
, bytes
));
1371 #endif /* HAVE_LIBZ */
1372 return (cups_write(fp
, s
, bytes
));
1376 memcpy(fp
->ptr
, s
, bytes
);
1384 * 'cupsFileRead()' - Read from a file.
1389 ssize_t
/* O - Number of bytes read or -1 on error */
1390 cupsFileRead(cups_file_t
*fp
, /* I - CUPS file */
1391 char *buf
, /* O - Buffer */
1392 size_t bytes
) /* I - Number of bytes to read */
1394 size_t total
; /* Total bytes read */
1395 ssize_t count
; /* Bytes read */
1398 DEBUG_printf(("cupsFileRead(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")\n", fp
, buf
,
1399 CUPS_LLCAST bytes
));
1402 * Range check input...
1405 if (!fp
|| !buf
|| bytes
< 0 || (fp
->mode
!= 'r' && fp
->mode
!= 's'))
1412 * Loop until all bytes are read...
1418 if (fp
->ptr
>= fp
->end
)
1419 if (cups_fill(fp
) <= 0)
1421 DEBUG_printf(("cupsFileRead: cups_fill() returned -1, total=" CUPS_LLFMT
"\n",
1422 CUPS_LLCAST total
));
1425 return ((ssize_t
)total
);
1430 count
= (ssize_t
)(fp
->end
- fp
->ptr
);
1431 if (count
> (ssize_t
)bytes
)
1432 count
= (ssize_t
)bytes
;
1434 memcpy(buf
, fp
->ptr
, count
);
1438 DEBUG_printf(("cupsFileRead: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1441 * Update the counts for the last read...
1450 * Return the total number of bytes read...
1453 DEBUG_printf(("cupsFileRead: total=%d\n", (int)total
));
1455 return ((ssize_t
)total
);
1460 * 'cupsFileRewind()' - Set the current file position to the beginning of the
1466 off_t
/* O - New file position or -1 on error */
1467 cupsFileRewind(cups_file_t
*fp
) /* I - CUPS file */
1470 * Range check input...
1473 DEBUG_printf(("cupsFileRewind(fp=%p)\n", fp
));
1474 DEBUG_printf(("cupsFileRewind: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1476 if (!fp
|| fp
->mode
!= 'r')
1480 * Handle special cases...
1483 if (fp
->bufpos
== 0)
1486 * No seeking necessary...
1497 DEBUG_printf(("cupsFileRewind: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1503 * Otherwise, seek in the file and cleanup any compression buffers...
1509 inflateEnd(&fp
->stream
);
1512 #endif /* HAVE_LIBZ */
1514 if (lseek(fp
->fd
, 0, SEEK_SET
))
1516 DEBUG_printf(("cupsFileRewind: lseek failed: %s\n", strerror(errno
)));
1526 DEBUG_printf(("cupsFileRewind: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1533 * 'cupsFileSeek()' - Seek in a file.
1538 off_t
/* O - New file position or -1 on error */
1539 cupsFileSeek(cups_file_t
*fp
, /* I - CUPS file */
1540 off_t pos
) /* I - Position in file */
1542 ssize_t bytes
; /* Number bytes in buffer */
1545 DEBUG_printf(("cupsFileSeek(fp=%p, pos=" CUPS_LLFMT
")\n", fp
,
1547 DEBUG_printf(("cupsFileSeek: fp->pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1548 DEBUG_printf(("cupsFileSeek: fp->ptr=%p, fp->end=%p\n", fp
->ptr
, fp
->end
));
1551 * Range check input...
1554 if (!fp
|| pos
< 0 || fp
->mode
!= 'r')
1558 * Handle special cases...
1562 return (cupsFileRewind(fp
));
1566 bytes
= (ssize_t
)(fp
->end
- fp
->buf
);
1568 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1571 * No seeking necessary...
1575 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1583 if (!fp
->compressed
&& !fp
->ptr
)
1586 * Preload a buffer to determine whether the file is compressed...
1589 if (cups_fill(fp
) < 0)
1592 #endif /* HAVE_LIBZ */
1595 * Seek forwards or backwards...
1600 DEBUG_printf(("cupsFileSeek: bytes=" CUPS_LLFMT
"\n", CUPS_LLCAST bytes
));
1602 if (pos
< fp
->bufpos
)
1605 * Need to seek backwards...
1608 DEBUG_puts("cupsFileSeek: SEEK BACKWARDS");
1613 inflateEnd(&fp
->stream
);
1615 lseek(fp
->fd
, 0, SEEK_SET
);
1621 while ((bytes
= cups_fill(fp
)) > 0)
1622 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1628 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1632 #endif /* HAVE_LIBZ */
1634 fp
->bufpos
= lseek(fp
->fd
, pos
, SEEK_SET
);
1635 fp
->pos
= fp
->bufpos
;
1639 DEBUG_printf(("cupsFileSeek: lseek() returned " CUPS_LLFMT
"...\n",
1640 CUPS_LLCAST fp
->pos
));
1646 * Need to seek forwards...
1649 DEBUG_puts("cupsFileSeek: SEEK FORWARDS");
1654 while ((bytes
= cups_fill(fp
)) > 0)
1656 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1663 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1667 #endif /* HAVE_LIBZ */
1669 fp
->bufpos
= lseek(fp
->fd
, pos
, SEEK_SET
);
1670 fp
->pos
= fp
->bufpos
;
1674 DEBUG_printf(("cupsFileSeek: lseek() returned " CUPS_LLFMT
"...\n",
1675 CUPS_LLCAST fp
->pos
));
1679 DEBUG_printf(("cupsFileSeek: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1686 * 'cupsFileStderr()' - Return a CUPS file associated with stderr.
1691 cups_file_t
* /* O - CUPS file */
1692 cupsFileStderr(void)
1694 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1698 * Open file descriptor 2 as needed...
1701 if (!cg
->stdio_files
[2])
1704 * Flush any pending output on the stdio file...
1710 * Open file descriptor 2...
1713 if ((cg
->stdio_files
[2] = cupsFileOpenFd(2, "w")) != NULL
)
1714 cg
->stdio_files
[2]->is_stdio
= 1;
1717 return (cg
->stdio_files
[2]);
1722 * 'cupsFileStdin()' - Return a CUPS file associated with stdin.
1727 cups_file_t
* /* O - CUPS file */
1730 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1734 * Open file descriptor 0 as needed...
1737 if (!cg
->stdio_files
[0])
1740 * Open file descriptor 0...
1743 if ((cg
->stdio_files
[0] = cupsFileOpenFd(0, "r")) != NULL
)
1744 cg
->stdio_files
[0]->is_stdio
= 1;
1747 return (cg
->stdio_files
[0]);
1752 * 'cupsFileStdout()' - Return a CUPS file associated with stdout.
1757 cups_file_t
* /* O - CUPS file */
1758 cupsFileStdout(void)
1760 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1764 * Open file descriptor 1 as needed...
1767 if (!cg
->stdio_files
[1])
1770 * Flush any pending output on the stdio file...
1776 * Open file descriptor 1...
1779 if ((cg
->stdio_files
[1] = cupsFileOpenFd(1, "w")) != NULL
)
1780 cg
->stdio_files
[1]->is_stdio
= 1;
1783 return (cg
->stdio_files
[1]);
1788 * 'cupsFileTell()' - Return the current file position.
1793 off_t
/* O - File position */
1794 cupsFileTell(cups_file_t
*fp
) /* I - CUPS file */
1796 DEBUG_printf(("cupsFileTell(fp=%p)\n", fp
));
1797 DEBUG_printf(("cupsFileTell: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST (fp
? fp
->pos
: -1)));
1799 return (fp
? fp
->pos
: 0);
1804 * 'cupsFileUnlock()' - Unlock access to a file.
1809 int /* O - 0 on success, -1 on error */
1810 cupsFileUnlock(cups_file_t
*fp
) /* I - CUPS file */
1816 DEBUG_printf(("cupsFileUnlock(fp=%p)\n", fp
));
1818 if (!fp
|| fp
->mode
== 's')
1826 return (locking(fp
->fd
, _LK_UNLCK
, 0));
1828 return (lockf(fp
->fd
, F_ULOCK
, 0));
1834 * 'cupsFileWrite()' - Write to a file.
1839 ssize_t
/* O - Number of bytes written or -1 on error */
1840 cupsFileWrite(cups_file_t
*fp
, /* I - CUPS file */
1841 const char *buf
, /* I - Buffer */
1842 size_t bytes
) /* I - Number of bytes to write */
1845 * Range check input...
1848 DEBUG_printf(("cupsFileWrite(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")\n",
1849 fp
, buf
, CUPS_LLCAST bytes
));
1851 if (!fp
|| !buf
|| bytes
< 0 || (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1858 * Write the buffer...
1861 if (fp
->mode
== 's')
1863 if (cups_write(fp
, buf
, bytes
) < 0)
1866 fp
->pos
+= (off_t
)bytes
;
1868 DEBUG_printf(("cupsFileWrite: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1870 return ((ssize_t
)bytes
);
1873 if ((fp
->ptr
+ bytes
) > fp
->end
)
1874 if (cupsFileFlush(fp
))
1877 fp
->pos
+= (off_t
)bytes
;
1879 DEBUG_printf(("cupsFileWrite: pos=" CUPS_LLFMT
"\n", CUPS_LLCAST fp
->pos
));
1881 if (bytes
> sizeof(fp
->buf
))
1885 return (cups_compress(fp
, buf
, bytes
));
1887 #endif /* HAVE_LIBZ */
1888 return (cups_write(fp
, buf
, bytes
));
1892 memcpy(fp
->ptr
, buf
, bytes
);
1894 return ((ssize_t
)bytes
);
1901 * 'cups_compress()' - Compress a buffer of data...
1904 static ssize_t
/* O - Number of bytes written or -1 */
1905 cups_compress(cups_file_t
*fp
, /* I - CUPS file */
1906 const char *buf
, /* I - Buffer */
1907 size_t bytes
) /* I - Number bytes */
1909 DEBUG_printf(("cups_compress(fp=%p, buf=%p, bytes=" CUPS_LLFMT
"\n", fp
, buf
,
1910 CUPS_LLCAST bytes
));
1916 fp
->crc
= crc32(fp
->crc
, (const Bytef
*)buf
, bytes
);
1919 * Deflate the bytes...
1922 fp
->stream
.next_in
= (Bytef
*)buf
;
1923 fp
->stream
.avail_in
= bytes
;
1925 while (fp
->stream
.avail_in
> 0)
1928 * Flush the current buffer...
1931 DEBUG_printf(("cups_compress: avail_in=%d, avail_out=%d\n",
1932 fp
->stream
.avail_in
, fp
->stream
.avail_out
));
1934 if (fp
->stream
.avail_out
< (int)(sizeof(fp
->cbuf
) / 8))
1936 if (cups_write(fp
, (char *)fp
->cbuf
, fp
->stream
.next_out
- fp
->cbuf
) < 0)
1939 fp
->stream
.next_out
= fp
->cbuf
;
1940 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
1943 deflate(&(fp
->stream
), Z_NO_FLUSH
);
1948 #endif /* HAVE_LIBZ */
1952 * 'cups_fill()' - Fill the input buffer...
1955 static ssize_t
/* O - Number of bytes or -1 */
1956 cups_fill(cups_file_t
*fp
) /* I - CUPS file */
1958 ssize_t bytes
; /* Number of bytes read */
1960 int status
; /* Decompression status */
1961 const unsigned char *ptr
, /* Pointer into buffer */
1962 *end
; /* End of buffer */
1963 #endif /* HAVE_LIBZ */
1966 DEBUG_printf(("cups_fill(fp=%p)\n", fp
));
1967 DEBUG_printf(("cups_fill: fp->ptr=%p, fp->end=%p, fp->buf=%p, "
1968 "fp->bufpos=" CUPS_LLFMT
", fp->eof=%d\n",
1969 fp
->ptr
, fp
->end
, fp
->buf
, CUPS_LLCAST fp
->bufpos
, fp
->eof
));
1971 if (fp
->ptr
&& fp
->end
)
1972 fp
->bufpos
+= fp
->end
- fp
->buf
;
1975 DEBUG_printf(("cups_fill: fp->compressed=%d\n", fp
->compressed
));
1977 while (!fp
->ptr
|| fp
->compressed
)
1980 * Check to see if we have read any data yet; if not, see if we have a
1981 * compressed file...
1987 * Reset the file position in case we are seeking...
1993 * Read the first bytes in the file to determine if we have a gzip'd
1997 if ((bytes
= cups_read(fp
, (char *)fp
->buf
, sizeof(fp
->buf
))) < 0)
2000 * Can't read from file!
2003 DEBUG_printf(("cups_fill: cups_read() returned " CUPS_LLFMT
"!\n",
2004 CUPS_LLCAST bytes
));
2009 if (bytes
< 10 || fp
->buf
[0] != 0x1f ||
2010 (fp
->buf
[1] & 255) != 0x8b ||
2011 fp
->buf
[2] != 8 || (fp
->buf
[3] & 0xe0) != 0)
2014 * Not a gzip'd file!
2018 fp
->end
= fp
->buf
+ bytes
;
2020 DEBUG_printf(("cups_fill: Returning " CUPS_LLFMT
"!\n",
2021 CUPS_LLCAST bytes
));
2027 * Parse header junk: extra data, original name, and comment...
2030 ptr
= (unsigned char *)fp
->buf
+ 10;
2031 end
= (unsigned char *)fp
->buf
+ bytes
;
2033 if (fp
->buf
[3] & 0x04)
2036 * Skip extra data...
2039 if ((ptr
+ 2) > end
)
2042 * Can't read from file!
2048 bytes
= ((unsigned char)ptr
[1] << 8) | (unsigned char)ptr
[0];
2054 * Can't read from file!
2061 if (fp
->buf
[3] & 0x08)
2064 * Skip original name data...
2067 while (ptr
< end
&& *ptr
)
2075 * Can't read from file!
2082 if (fp
->buf
[3] & 0x10)
2085 * Skip comment data...
2088 while (ptr
< end
&& *ptr
)
2096 * Can't read from file!
2103 if (fp
->buf
[3] & 0x02)
2106 * Skip header CRC data...
2114 * Can't read from file!
2122 * Copy the flate-compressed data to the compression buffer...
2125 if ((bytes
= end
- ptr
) > 0)
2126 memcpy(fp
->cbuf
, ptr
, bytes
);
2129 * Setup the decompressor data...
2132 fp
->stream
.zalloc
= (alloc_func
)0;
2133 fp
->stream
.zfree
= (free_func
)0;
2134 fp
->stream
.opaque
= (voidpf
)0;
2135 fp
->stream
.next_in
= (Bytef
*)fp
->cbuf
;
2136 fp
->stream
.next_out
= NULL
;
2137 fp
->stream
.avail_in
= bytes
;
2138 fp
->stream
.avail_out
= 0;
2139 fp
->crc
= crc32(0L, Z_NULL
, 0);
2141 if (inflateInit2(&(fp
->stream
), -15) != Z_OK
)
2150 * If we have reached end-of-file, return immediately...
2157 * Fill the decompression buffer as needed...
2160 if (fp
->stream
.avail_in
== 0)
2162 if ((bytes
= cups_read(fp
, (char *)fp
->cbuf
, sizeof(fp
->cbuf
))) <= 0)
2165 fp
->stream
.next_in
= fp
->cbuf
;
2166 fp
->stream
.avail_in
= bytes
;
2170 * Decompress data from the buffer...
2173 fp
->stream
.next_out
= (Bytef
*)fp
->buf
;
2174 fp
->stream
.avail_out
= sizeof(fp
->buf
);
2176 status
= inflate(&(fp
->stream
), Z_NO_FLUSH
);
2178 if (fp
->stream
.next_out
> (Bytef
*)fp
->buf
)
2179 fp
->crc
= crc32(fp
->crc
, (Bytef
*)fp
->buf
,
2180 fp
->stream
.next_out
- (Bytef
*)fp
->buf
);
2182 if (status
== Z_STREAM_END
)
2185 * Read the CRC and length...
2188 unsigned char trailer
[8]; /* Trailer bytes */
2189 uLong tcrc
; /* Trailer CRC */
2192 if (read(fp
->fd
, trailer
, sizeof(trailer
)) < sizeof(trailer
))
2195 * Can't get it, so mark end-of-file...
2202 tcrc
= (((((trailer
[3] << 8) | trailer
[2]) << 8) | trailer
[1]) << 8) |
2205 if (tcrc
!= fp
->crc
)
2208 * Bad CRC, mark end-of-file...
2211 DEBUG_printf(("cups_fill: tcrc=%08x, fp->crc=%08x\n",
2212 (unsigned int)tcrc
, (unsigned int)fp
->crc
));
2220 * Otherwise, reset the compressed flag so that we re-read the
2228 bytes
= sizeof(fp
->buf
) - fp
->stream
.avail_out
;
2231 * Return the decompressed data...
2235 fp
->end
= fp
->buf
+ bytes
;
2241 #endif /* HAVE_LIBZ */
2244 * Read a buffer's full of data...
2247 if ((bytes
= cups_read(fp
, fp
->buf
, sizeof(fp
->buf
))) <= 0)
2250 * Can't read from file!
2261 * Return the bytes we read...
2266 fp
->end
= fp
->buf
+ bytes
;
2273 * 'cups_read()' - Read from a file descriptor.
2276 static ssize_t
/* O - Number of bytes read or -1 */
2277 cups_read(cups_file_t
*fp
, /* I - CUPS file */
2278 char *buf
, /* I - Buffer */
2279 size_t bytes
) /* I - Number bytes */
2281 ssize_t total
; /* Total bytes read */
2284 DEBUG_printf(("cups_read(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")\n", fp
, buf
,
2285 CUPS_LLCAST bytes
));
2288 * Loop until we read at least 0 bytes...
2294 if (fp
->mode
== 's')
2295 total
= (ssize_t
)recv(fp
->fd
, buf
, (unsigned)bytes
, 0);
2297 total
= (ssize_t
)read(fp
->fd
, buf
, (unsigned)bytes
);
2299 if (fp
->mode
== 's')
2300 total
= recv(fp
->fd
, buf
, bytes
, 0);
2302 total
= read(fp
->fd
, buf
, bytes
);
2305 DEBUG_printf(("cups_read: total=" CUPS_LLFMT
"\n", CUPS_LLCAST total
));
2311 * Reads can be interrupted by signals and unavailable resources...
2314 if (errno
== EAGAIN
|| errno
== EINTR
)
2321 * Return the total number of bytes read...
2329 * 'cups_write()' - Write to a file descriptor.
2332 static ssize_t
/* O - Number of bytes written or -1 */
2333 cups_write(cups_file_t
*fp
, /* I - CUPS file */
2334 const char *buf
, /* I - Buffer */
2335 size_t bytes
) /* I - Number bytes */
2337 size_t total
; /* Total bytes written */
2338 ssize_t count
; /* Count this time */
2341 DEBUG_printf(("cups_write(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")\n", fp
, buf
,
2342 CUPS_LLCAST bytes
));
2345 * Loop until all bytes are written...
2352 if (fp
->mode
== 's')
2353 count
= (ssize_t
)send(fp
->fd
, buf
, (unsigned)bytes
, 0);
2355 count
= (ssize_t
)write(fp
->fd
, buf
, (unsigned)bytes
);
2357 if (fp
->mode
== 's')
2358 count
= send(fp
->fd
, buf
, bytes
, 0);
2360 count
= write(fp
->fd
, buf
, bytes
);
2363 DEBUG_printf(("cups_write: count=" CUPS_LLFMT
"\n", CUPS_LLCAST count
));
2368 * Writes can be interrupted by signals and unavailable resources...
2371 if (errno
== EAGAIN
|| errno
== EINTR
)
2378 * Update the counts for the last write call...
2387 * Return the total number of bytes written...
2390 return ((ssize_t
)total
);
2395 * End of "$Id: file.c 7672 2008-06-18 22:03:02Z mike $".