]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/file.c
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-2009 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...
61 #include "file-private.h"
69 static ssize_t
cups_compress(cups_file_t
*fp
, const char *buf
, size_t bytes
);
70 #endif /* HAVE_LIBZ */
71 static ssize_t
cups_fill(cups_file_t
*fp
);
72 static ssize_t
cups_read(cups_file_t
*fp
, char *buf
, size_t bytes
);
73 static ssize_t
cups_write(cups_file_t
*fp
, const char *buf
, size_t bytes
);
77 * 'cupsFileClose()' - Close a CUPS file.
79 * @since CUPS 1.2/Mac OS X 10.5@
82 int /* O - 0 on success, -1 on error */
83 cupsFileClose(cups_file_t
*fp
) /* I - CUPS file */
85 int fd
; /* File descriptor */
86 char mode
; /* Open mode */
87 int status
; /* Return status */
88 int is_stdio
; /* Is a stdio file? */
91 DEBUG_printf(("cupsFileClose(fp=%p)", fp
));
101 * Flush pending write data...
105 status
= cupsFileFlush(fp
);
110 if (fp
->compressed
&& status
>= 0)
115 * Free decompression data...
118 inflateEnd(&fp
->stream
);
123 * Flush any remaining compressed data...
126 unsigned char trailer
[8]; /* Trailer CRC and length */
127 int done
; /* Done writing... */
130 fp
->stream
.avail_in
= 0;
134 if (fp
->stream
.next_out
> fp
->cbuf
)
136 if (cups_write(fp
, (char *)fp
->cbuf
,
137 fp
->stream
.next_out
- fp
->cbuf
) < 0)
140 fp
->stream
.next_out
= fp
->cbuf
;
141 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
144 if (done
|| status
< 0)
147 done
= deflate(&fp
->stream
, Z_FINISH
) == Z_STREAM_END
&&
148 fp
->stream
.next_out
== fp
->cbuf
;
152 * Write the CRC and length...
155 trailer
[0] = fp
->crc
;
156 trailer
[1] = fp
->crc
>> 8;
157 trailer
[2] = fp
->crc
>> 16;
158 trailer
[3] = fp
->crc
>> 24;
159 trailer
[4] = fp
->pos
;
160 trailer
[5] = fp
->pos
>> 8;
161 trailer
[6] = fp
->pos
>> 16;
162 trailer
[7] = fp
->pos
>> 24;
164 if (cups_write(fp
, (char *)trailer
, 8) < 0)
168 * Free all memory used by the compression stream...
171 deflateEnd(&(fp
->stream
));
174 #endif /* HAVE_LIBZ */
177 * Save the file descriptor we used and free memory...
182 is_stdio
= fp
->is_stdio
;
184 if (fp
->printf_buffer
)
185 free(fp
->printf_buffer
);
190 * Close the file, returning the close status...
195 if (closesocket(fd
) < 0)
209 * 'cupsFileCompression()' - Return whether a file is compressed.
211 * @since CUPS 1.2/Mac OS X 10.5@
214 int /* O - @code CUPS_FILE_NONE@ or @code CUPS_FILE_GZIP@ */
215 cupsFileCompression(cups_file_t
*fp
) /* I - CUPS file */
217 return (fp
? fp
->compressed
: CUPS_FILE_NONE
);
222 * 'cupsFileEOF()' - Return the end-of-file status.
224 * @since CUPS 1.2/Mac OS X 10.5@
227 int /* O - 1 on end of file, 0 otherwise */
228 cupsFileEOF(cups_file_t
*fp
) /* I - CUPS file */
230 return (fp
? fp
->eof
: 1);
235 * 'cupsFileFind()' - Find a file using the specified path.
237 * This function allows the paths in the path string to be separated by
238 * colons (UNIX standard) or semicolons (Windows standard) and stores the
239 * result in the buffer supplied. If the file cannot be found in any of
240 * the supplied paths, @code NULL@ is returned. A @code NULL@ path only
241 * matches the current directory.
243 * @since CUPS 1.2/Mac OS X 10.5@
246 const char * /* O - Full path to file or @code NULL@ if not found */
247 cupsFileFind(const char *filename
, /* I - File to find */
248 const char *path
, /* I - Colon/semicolon-separated path */
249 int executable
, /* I - 1 = executable files, 0 = any file/dir */
250 char *buffer
, /* I - Filename buffer */
251 int bufsize
) /* I - Size of filename buffer */
253 char *bufptr
, /* Current position in buffer */
254 *bufend
; /* End of buffer */
258 * Range check input...
261 DEBUG_printf(("cupsFileFind(filename=\"%s\", path=\"%s\", executable=%d, "
262 "buffer=%p, bufsize=%d)", filename
, path
, executable
, buffer
,
265 if (!filename
|| !buffer
|| bufsize
< 2)
271 * No path, so check current directory...
274 if (!access(filename
, 0))
276 strlcpy(buffer
, filename
, bufsize
);
284 * Now check each path and return the first match...
287 bufend
= buffer
+ bufsize
- 1;
293 if (*path
== ';' || (*path
== ':' && ((bufptr
- buffer
) > 1 || !isalpha(buffer
[0] & 255))))
295 if (*path
== ';' || *path
== ':')
298 if (bufptr
> buffer
&& bufptr
[-1] != '/' && bufptr
< bufend
)
301 strlcpy(bufptr
, filename
, bufend
- bufptr
);
304 if (!access(buffer
, 0))
306 if (!access(buffer
, executable
? X_OK
: 0))
309 DEBUG_printf(("1cupsFileFind: Returning \"%s\"", buffer
));
315 else if (bufptr
< bufend
)
322 * Check the last path...
325 if (bufptr
> buffer
&& bufptr
[-1] != '/' && bufptr
< bufend
)
328 strlcpy(bufptr
, filename
, bufend
- bufptr
);
330 if (!access(buffer
, 0))
332 DEBUG_printf(("1cupsFileFind: Returning \"%s\"", buffer
));
337 DEBUG_puts("1cupsFileFind: Returning NULL");
344 * 'cupsFileFlush()' - Flush pending output.
346 * @since CUPS 1.2/Mac OS X 10.5@
349 int /* O - 0 on success, -1 on error */
350 cupsFileFlush(cups_file_t
*fp
) /* I - CUPS file */
352 ssize_t bytes
; /* Bytes to write */
355 DEBUG_printf(("cupsFileFlush(fp=%p)", fp
));
358 * Range check input...
361 if (!fp
|| fp
->mode
!= 'w')
363 DEBUG_puts("1cupsFileFlush: Attempt to flush a read-only file...");
367 bytes
= (ssize_t
)(fp
->ptr
- fp
->buf
);
369 DEBUG_printf(("2cupsFileFlush: Flushing " CUPS_LLFMT
" bytes...",
376 bytes
= cups_compress(fp
, fp
->buf
, bytes
);
378 #endif /* HAVE_LIBZ */
379 bytes
= cups_write(fp
, fp
->buf
, bytes
);
392 * 'cupsFileGetChar()' - Get a single character from a file.
394 * @since CUPS 1.2/Mac OS X 10.5@
397 int /* O - Character or -1 on end of file */
398 cupsFileGetChar(cups_file_t
*fp
) /* I - CUPS file */
401 * Range check input...
404 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's'))
406 DEBUG_puts("3cupsFileGetChar: Bad arguments!");
411 * If the input buffer is empty, try to read more data...
414 if (fp
->ptr
>= fp
->end
)
415 if (cups_fill(fp
) < 0)
417 DEBUG_puts("3cupsFileGetChar: Unable to fill buffer!");
422 * Return the next character in the buffer...
425 DEBUG_printf(("3cupsFileGetChar: Returning %d...", *(fp
->ptr
) & 255));
429 DEBUG_printf(("4cupsFileGetChar: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
431 return (*(fp
->ptr
)++ & 255);
436 * 'cupsFileGetConf()' - Get a line from a configuration file...
438 * @since CUPS 1.2/Mac OS X 10.5@
441 char * /* O - Line read or @code NULL@ on end of file or error */
442 cupsFileGetConf(cups_file_t
*fp
, /* I - CUPS file */
443 char *buf
, /* O - String buffer */
444 size_t buflen
, /* I - Size of string buffer */
445 char **value
, /* O - Pointer to value */
446 int *linenum
) /* IO - Current line number */
448 char *ptr
; /* Pointer into line */
452 * Range check input...
455 DEBUG_printf(("2cupsFileGetConf(fp=%p, buf=%p, buflen=" CUPS_LLFMT
456 ", value=%p, linenum=%p)", fp
, buf
, CUPS_LLCAST buflen
,
459 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') ||
460 !buf
|| buflen
< 2 || !value
)
469 * Read the next non-comment line...
474 while (cupsFileGets(fp
, buf
, buflen
))
479 * Strip any comments...
482 if ((ptr
= strchr(buf
, '#')) != NULL
)
484 if (ptr
> buf
&& ptr
[-1] == '\\')
487 _cups_strcpy(ptr
- 1, ptr
);
491 // Strip the comment and any trailing whitespace...
494 if (!isspace(ptr
[-1] & 255))
505 * Strip leading whitespace...
508 for (ptr
= buf
; isspace(*ptr
& 255); ptr
++);
511 _cups_strcpy(buf
, ptr
);
514 * See if there is anything left...
520 * Yes, grab any value and return...
523 for (ptr
= buf
; *ptr
; ptr
++)
524 if (isspace(*ptr
& 255))
530 * Have a value, skip any other spaces...
533 while (isspace(*ptr
& 255))
540 * Strip trailing whitespace and > for lines that begin with <...
543 ptr
+= strlen(ptr
) - 1;
545 if (buf
[0] == '<' && *ptr
== '>')
547 else if (buf
[0] == '<' && *ptr
!= '>')
557 while (ptr
> *value
&& isspace(*ptr
& 255))
574 * 'cupsFileGetLine()' - Get a CR and/or LF-terminated line that may
575 * contain binary data.
577 * This function differs from @link cupsFileGets@ in that the trailing CR
578 * and LF are preserved, as is any binary data on the line. The buffer is
579 * nul-terminated, however you should use the returned length to determine
580 * the number of bytes on the line.
582 * @since CUPS 1.2/Mac OS X 10.5@
585 size_t /* O - Number of bytes on line or 0 on end of file */
586 cupsFileGetLine(cups_file_t
*fp
, /* I - File to read from */
587 char *buf
, /* I - Buffer */
588 size_t buflen
) /* I - Size of buffer */
590 int ch
; /* Character from file */
591 char *ptr
, /* Current position in line buffer */
592 *end
; /* End of line buffer */
596 * Range check input...
599 DEBUG_printf(("2cupsFileGetLine(fp=%p, buf=%p, buflen=" CUPS_LLFMT
")",
600 fp
, buf
, CUPS_LLCAST buflen
));
602 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') || !buf
|| buflen
< 3)
606 * Now loop until we have a valid line...
609 for (ptr
= buf
, end
= buf
+ buflen
- 2; ptr
< end
;)
611 if (fp
->ptr
>= fp
->end
)
612 if (cups_fill(fp
) <= 0)
615 *ptr
++ = ch
= *(fp
->ptr
)++;
624 if (fp
->ptr
>= fp
->end
)
625 if (cups_fill(fp
) <= 0)
628 if (*(fp
->ptr
) == '\n')
630 *ptr
++ = *(fp
->ptr
)++;
639 * Line feed ends a line...
648 DEBUG_printf(("4cupsFileGetLine: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
655 * 'cupsFileGets()' - Get a CR and/or LF-terminated line.
657 * @since CUPS 1.2/Mac OS X 10.5@
660 char * /* O - Line read or @code NULL@ on end of file or error */
661 cupsFileGets(cups_file_t
*fp
, /* I - CUPS file */
662 char *buf
, /* O - String buffer */
663 size_t buflen
) /* I - Size of string buffer */
665 int ch
; /* Character from file */
666 char *ptr
, /* Current position in line buffer */
667 *end
; /* End of line buffer */
671 * Range check input...
674 DEBUG_printf(("2cupsFileGets(fp=%p, buf=%p, buflen=" CUPS_LLFMT
")", fp
, buf
,
675 CUPS_LLCAST buflen
));
677 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's') || !buf
|| buflen
< 2)
681 * Now loop until we have a valid line...
684 for (ptr
= buf
, end
= buf
+ buflen
- 1; ptr
< end
;)
686 if (fp
->ptr
>= fp
->end
)
687 if (cups_fill(fp
) <= 0)
704 if (fp
->ptr
>= fp
->end
)
705 if (cups_fill(fp
) <= 0)
708 if (*(fp
->ptr
) == '\n')
719 * Line feed ends a line...
730 DEBUG_printf(("4cupsFileGets: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
737 * 'cupsFileLock()' - Temporarily lock access to a file.
739 * @since CUPS 1.2/Mac OS X 10.5@
742 int /* O - 0 on success, -1 on error */
743 cupsFileLock(cups_file_t
*fp
, /* I - CUPS file */
744 int block
) /* I - 1 to wait for the lock, 0 to fail right away */
750 if (!fp
|| fp
->mode
== 's')
758 return (locking(fp
->fd
, block
? _LK_LOCK
: _LK_NBLCK
, 0));
760 return (lockf(fp
->fd
, block
? F_LOCK
: F_TLOCK
, 0));
766 * 'cupsFileNumber()' - Return the file descriptor associated with a CUPS file.
768 * @since CUPS 1.2/Mac OS X 10.5@
771 int /* O - File descriptor */
772 cupsFileNumber(cups_file_t
*fp
) /* I - CUPS file */
782 * 'cupsFileOpen()' - Open a CUPS file.
784 * The "mode" parameter can be "r" to read, "w" to write, overwriting any
785 * existing file, "a" to append to an existing file or create a new file,
786 * or "s" to open a socket connection.
788 * When opening for writing ("w"), an optional number from 1 to 9 can be
789 * supplied which enables Flate compression of the file. Compression is
790 * not supported for the "a" (append) mode.
792 * When opening a socket connection, the filename is a string of the form
793 * "address:port" or "hostname:port". The socket will make an IPv4 or IPv6
794 * connection as needed, generally preferring IPv6 connections when there is
797 * @since CUPS 1.2/Mac OS X 10.5@
800 cups_file_t
* /* O - CUPS file or @code NULL@ if the file or socket cannot be opened */
801 cupsFileOpen(const char *filename
, /* I - Name of file */
802 const char *mode
) /* I - Open mode */
804 cups_file_t
*fp
; /* New CUPS file */
805 int fd
; /* File descriptor */
806 char hostname
[1024], /* Hostname */
807 *portname
; /* Port "name" (number or service) */
808 http_addrlist_t
*addrlist
; /* Host address list */
811 DEBUG_printf(("cupsFileOpen(filename=\"%s\", mode=\"%s\")", filename
,
815 * Range check input...
818 if (!filename
|| !mode
||
819 (*mode
!= 'r' && *mode
!= 'w' && *mode
!= 'a' && *mode
!= 's') ||
820 (*mode
== 'a' && isdigit(mode
[1] & 255)))
829 case 'a' : /* Append file */
830 fd
= open(filename
, O_RDWR
| O_CREAT
| O_APPEND
| O_LARGEFILE
| O_BINARY
, 0666);
833 case 'r' : /* Read file */
834 fd
= open(filename
, O_RDONLY
| O_LARGEFILE
| O_BINARY
, 0);
837 case 'w' : /* Write file */
838 fd
= open(filename
, O_WRONLY
| O_TRUNC
| O_CREAT
| O_LARGEFILE
| O_BINARY
, 0666);
841 case 's' : /* Read/write socket */
842 strlcpy(hostname
, filename
, sizeof(hostname
));
843 if ((portname
= strrchr(hostname
, ':')) != NULL
)
849 * Lookup the hostname and service...
852 if ((addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, portname
)) == NULL
)
856 * Connect to the server...
859 if (!httpAddrConnect(addrlist
, &fd
))
861 httpAddrFreeList(addrlist
);
865 httpAddrFreeList(addrlist
);
868 default : /* Remove bogus compiler warning... */
876 * Create the CUPS file structure...
879 if ((fp
= cupsFileOpenFd(fd
, mode
)) == NULL
)
895 * 'cupsFileOpenFd()' - Open a CUPS file using a file descriptor.
897 * The "mode" parameter can be "r" to read, "w" to write, "a" to append,
898 * or "s" to treat the file descriptor as a bidirectional socket connection.
900 * When opening for writing ("w"), an optional number from 1 to 9 can be
901 * supplied which enables Flate compression of the file. Compression is
902 * not supported for the "a" (append) mode.
904 * @since CUPS 1.2/Mac OS X 10.5@
907 cups_file_t
* /* O - CUPS file or @code NULL@ if the file could not be opened */
908 cupsFileOpenFd(int fd
, /* I - File descriptor */
909 const char *mode
) /* I - Open mode */
911 cups_file_t
*fp
; /* New CUPS file */
914 DEBUG_printf(("cupsFileOpenFd(fd=%d, mode=\"%s\")", fd
, mode
));
917 * Range check input...
920 if (fd
< 0 || !mode
||
921 (*mode
!= 'r' && *mode
!= 'w' && *mode
!= 'a' && *mode
!= 's') ||
922 (*mode
== 'a' && isdigit(mode
[1] & 255)))
929 if ((fp
= calloc(1, sizeof(cups_file_t
))) == NULL
)
941 fp
->pos
= lseek(fd
, 0, SEEK_END
);
946 fp
->end
= fp
->buf
+ sizeof(fp
->buf
);
949 if (mode
[1] >= '1' && mode
[1] <= '9')
952 * Open a compressed stream, so write the standard gzip file
956 unsigned char header
[10]; /* gzip file header */
957 time_t curtime
; /* Current time */
960 curtime
= time(NULL
);
963 header
[2] = Z_DEFLATED
;
966 header
[5] = curtime
>> 8;
967 header
[6] = curtime
>> 16;
968 header
[7] = curtime
>> 24;
972 cups_write(fp
, (char *)header
, 10);
975 * Initialize the compressor...
978 deflateInit2(&(fp
->stream
), mode
[1] - '0', Z_DEFLATED
, -15, 8,
981 fp
->stream
.next_out
= fp
->cbuf
;
982 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
984 fp
->crc
= crc32(0L, Z_NULL
, 0);
986 #endif /* HAVE_LIBZ */
997 default : /* Remove bogus compiler warning... */
1002 * Don't pass this file to child processes...
1006 fcntl(fp
->fd
, F_SETFD
, fcntl(fp
->fd
, F_GETFD
) | FD_CLOEXEC
);
1014 * 'cupsFilePeekChar()' - Peek at the next character from a file.
1016 * @since CUPS 1.2/Mac OS X 10.5@
1019 int /* O - Character or -1 on end of file */
1020 cupsFilePeekChar(cups_file_t
*fp
) /* I - CUPS file */
1023 * Range check input...
1026 if (!fp
|| (fp
->mode
!= 'r' && fp
->mode
!= 's'))
1030 * If the input buffer is empty, try to read more data...
1033 if (fp
->ptr
>= fp
->end
)
1034 if (cups_fill(fp
) < 0)
1038 * Return the next character in the buffer...
1041 return (*(fp
->ptr
) & 255);
1046 * 'cupsFilePrintf()' - Write a formatted string.
1048 * @since CUPS 1.2/Mac OS X 10.5@
1051 int /* O - Number of bytes written or -1 on error */
1052 cupsFilePrintf(cups_file_t
*fp
, /* I - CUPS file */
1053 const char *format
, /* I - Printf-style format string */
1054 ...) /* I - Additional args as necessary */
1056 va_list ap
; /* Argument list */
1057 ssize_t bytes
; /* Formatted size */
1060 DEBUG_printf(("2cupsFilePrintf(fp=%p, format=\"%s\", ...)", fp
, format
));
1062 if (!fp
|| !format
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1065 if (!fp
->printf_buffer
)
1068 * Start with an 1k printf buffer...
1071 if ((fp
->printf_buffer
= malloc(1024)) == NULL
)
1074 fp
->printf_size
= 1024;
1077 va_start(ap
, format
);
1078 bytes
= vsnprintf(fp
->printf_buffer
, fp
->printf_size
, format
, ap
);
1081 if (bytes
>= fp
->printf_size
)
1084 * Expand the printf buffer...
1087 char *temp
; /* Temporary buffer pointer */
1093 if ((temp
= realloc(fp
->printf_buffer
, bytes
+ 1)) == NULL
)
1096 fp
->printf_buffer
= temp
;
1097 fp
->printf_size
= bytes
+ 1;
1099 va_start(ap
, format
);
1100 bytes
= vsnprintf(fp
->printf_buffer
, fp
->printf_size
, format
, ap
);
1104 if (fp
->mode
== 's')
1106 if (cups_write(fp
, fp
->printf_buffer
, bytes
) < 0)
1111 DEBUG_printf(("4cupsFilePrintf: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1116 if ((fp
->ptr
+ bytes
) > fp
->end
)
1117 if (cupsFileFlush(fp
))
1122 DEBUG_printf(("4cupsFilePrintf: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1124 if (bytes
> sizeof(fp
->buf
))
1128 return (cups_compress(fp
, fp
->printf_buffer
, bytes
));
1130 #endif /* HAVE_LIBZ */
1131 return (cups_write(fp
, fp
->printf_buffer
, bytes
));
1135 memcpy(fp
->ptr
, fp
->printf_buffer
, bytes
);
1143 * 'cupsFilePutChar()' - Write a character.
1145 * @since CUPS 1.2/Mac OS X 10.5@
1148 int /* O - 0 on success, -1 on error */
1149 cupsFilePutChar(cups_file_t
*fp
, /* I - CUPS file */
1150 int c
) /* I - Character to write */
1153 * Range check input...
1156 if (!fp
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1159 if (fp
->mode
== 's')
1162 * Send character immediately over socket...
1165 char ch
; /* Output character */
1170 if (send(fp
->fd
, &ch
, 1, 0) < 1)
1179 if (fp
->ptr
>= fp
->end
)
1180 if (cupsFileFlush(fp
))
1188 DEBUG_printf(("4cupsFilePutChar: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1195 * 'cupsFilePutConf()' - Write a configuration line.
1197 * This function handles any comment escaping of the value.
1199 * @since CUPS 1.4/Mac OS X 10.6@
1202 ssize_t
/* O - Number of bytes written or -1 on error */
1203 cupsFilePutConf(cups_file_t
*fp
, /* I - CUPS file */
1204 const char *directive
, /* I - Directive */
1205 const char *value
) /* I - Value */
1207 ssize_t bytes
, /* Number of bytes written */
1208 temp
; /* Temporary byte count */
1209 const char *ptr
; /* Pointer into value */
1212 if (!fp
|| !directive
|| !*directive
)
1215 if ((bytes
= cupsFilePuts(fp
, directive
)) < 0)
1218 if (cupsFilePutChar(fp
, ' ') < 0)
1222 if (value
&& *value
)
1224 if ((ptr
= strchr(value
, '#')) != NULL
)
1227 * Need to quote the first # in the info string...
1230 if ((temp
= cupsFileWrite(fp
, value
, ptr
- value
)) < 0)
1234 if (cupsFilePutChar(fp
, '\\') < 0)
1238 if ((temp
= cupsFilePuts(fp
, ptr
)) < 0)
1242 else if ((temp
= cupsFilePuts(fp
, value
)) < 0)
1248 if (cupsFilePutChar(fp
, '\n') < 0)
1256 * 'cupsFilePuts()' - Write a string.
1258 * Like the @code fputs@ function, no newline is appended to the string.
1260 * @since CUPS 1.2/Mac OS X 10.5@
1263 int /* O - Number of bytes written or -1 on error */
1264 cupsFilePuts(cups_file_t
*fp
, /* I - CUPS file */
1265 const char *s
) /* I - String to write */
1267 ssize_t bytes
; /* Bytes to write */
1271 * Range check input...
1274 if (!fp
|| !s
|| (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1278 * Write the string...
1281 bytes
= (int)strlen(s
);
1283 if (fp
->mode
== 's')
1285 if (cups_write(fp
, s
, bytes
) < 0)
1290 DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1295 if ((fp
->ptr
+ bytes
) > fp
->end
)
1296 if (cupsFileFlush(fp
))
1301 DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1303 if (bytes
> sizeof(fp
->buf
))
1307 return (cups_compress(fp
, s
, bytes
));
1309 #endif /* HAVE_LIBZ */
1310 return (cups_write(fp
, s
, bytes
));
1314 memcpy(fp
->ptr
, s
, bytes
);
1322 * 'cupsFileRead()' - Read from a file.
1324 * @since CUPS 1.2/Mac OS X 10.5@
1327 ssize_t
/* O - Number of bytes read or -1 on error */
1328 cupsFileRead(cups_file_t
*fp
, /* I - CUPS file */
1329 char *buf
, /* O - Buffer */
1330 size_t bytes
) /* I - Number of bytes to read */
1332 size_t total
; /* Total bytes read */
1333 ssize_t count
; /* Bytes read */
1336 DEBUG_printf(("2cupsFileRead(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")", fp
, buf
,
1337 CUPS_LLCAST bytes
));
1340 * Range check input...
1343 if (!fp
|| !buf
|| bytes
< 0 || (fp
->mode
!= 'r' && fp
->mode
!= 's'))
1350 * Loop until all bytes are read...
1356 if (fp
->ptr
>= fp
->end
)
1357 if (cups_fill(fp
) <= 0)
1359 DEBUG_printf(("4cupsFileRead: cups_fill() returned -1, total="
1360 CUPS_LLFMT
, CUPS_LLCAST total
));
1363 return ((ssize_t
)total
);
1368 count
= (ssize_t
)(fp
->end
- fp
->ptr
);
1369 if (count
> (ssize_t
)bytes
)
1370 count
= (ssize_t
)bytes
;
1372 memcpy(buf
, fp
->ptr
, count
);
1376 DEBUG_printf(("4cupsFileRead: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1379 * Update the counts for the last read...
1388 * Return the total number of bytes read...
1391 DEBUG_printf(("3cupsFileRead: total=" CUPS_LLFMT
, CUPS_LLCAST total
));
1393 return ((ssize_t
)total
);
1398 * 'cupsFileRewind()' - Set the current file position to the beginning of the
1401 * @since CUPS 1.2/Mac OS X 10.5@
1404 off_t
/* O - New file position or -1 on error */
1405 cupsFileRewind(cups_file_t
*fp
) /* I - CUPS file */
1408 * Range check input...
1411 DEBUG_printf(("cupsFileRewind(fp=%p)", fp
));
1412 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1414 if (!fp
|| fp
->mode
!= 'r')
1418 * Handle special cases...
1421 if (fp
->bufpos
== 0)
1424 * No seeking necessary...
1435 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1441 * Otherwise, seek in the file and cleanup any compression buffers...
1447 inflateEnd(&fp
->stream
);
1450 #endif /* HAVE_LIBZ */
1452 if (lseek(fp
->fd
, 0, SEEK_SET
))
1454 DEBUG_printf(("1cupsFileRewind: lseek failed: %s", strerror(errno
)));
1464 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1471 * 'cupsFileSeek()' - Seek in a file.
1473 * @since CUPS 1.2/Mac OS X 10.5@
1476 off_t
/* O - New file position or -1 on error */
1477 cupsFileSeek(cups_file_t
*fp
, /* I - CUPS file */
1478 off_t pos
) /* I - Position in file */
1480 ssize_t bytes
; /* Number bytes in buffer */
1483 DEBUG_printf(("cupsFileSeek(fp=%p, pos=" CUPS_LLFMT
")", fp
,
1485 DEBUG_printf(("2cupsFileSeek: fp->pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1486 DEBUG_printf(("2cupsFileSeek: fp->ptr=%p, fp->end=%p", fp
->ptr
, fp
->end
));
1489 * Range check input...
1492 if (!fp
|| pos
< 0 || fp
->mode
!= 'r')
1496 * Handle special cases...
1500 return (cupsFileRewind(fp
));
1504 bytes
= (ssize_t
)(fp
->end
- fp
->buf
);
1506 DEBUG_printf(("2cupsFileSeek: bytes=" CUPS_LLFMT
, CUPS_LLCAST bytes
));
1508 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1511 * No seeking necessary...
1515 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1523 if (!fp
->compressed
&& !fp
->ptr
)
1526 * Preload a buffer to determine whether the file is compressed...
1529 if (cups_fill(fp
) < 0)
1532 #endif /* HAVE_LIBZ */
1535 * Seek forwards or backwards...
1540 if (pos
< fp
->bufpos
)
1543 * Need to seek backwards...
1546 DEBUG_puts("2cupsFileSeek: SEEK BACKWARDS");
1551 inflateEnd(&fp
->stream
);
1553 lseek(fp
->fd
, 0, SEEK_SET
);
1559 while ((bytes
= cups_fill(fp
)) > 0)
1560 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1566 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1570 #endif /* HAVE_LIBZ */
1572 fp
->bufpos
= lseek(fp
->fd
, pos
, SEEK_SET
);
1573 fp
->pos
= fp
->bufpos
;
1577 DEBUG_printf(("2cupsFileSeek: lseek() returned " CUPS_LLFMT
,
1578 CUPS_LLCAST fp
->pos
));
1584 * Need to seek forwards...
1587 DEBUG_puts("2cupsFileSeek: SEEK FORWARDS");
1592 while ((bytes
= cups_fill(fp
)) > 0)
1594 if (pos
>= fp
->bufpos
&& pos
< (fp
->bufpos
+ bytes
))
1601 fp
->ptr
= fp
->buf
+ pos
- fp
->bufpos
;
1605 #endif /* HAVE_LIBZ */
1607 fp
->bufpos
= lseek(fp
->fd
, pos
, SEEK_SET
);
1608 fp
->pos
= fp
->bufpos
;
1612 DEBUG_printf(("2cupsFileSeek: lseek() returned " CUPS_LLFMT
,
1613 CUPS_LLCAST fp
->pos
));
1617 DEBUG_printf(("2cupsFileSeek: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1624 * 'cupsFileStderr()' - Return a CUPS file associated with stderr.
1626 * @since CUPS 1.2/Mac OS X 10.5@
1629 cups_file_t
* /* O - CUPS file */
1630 cupsFileStderr(void)
1632 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1636 * Open file descriptor 2 as needed...
1639 if (!cg
->stdio_files
[2])
1642 * Flush any pending output on the stdio file...
1648 * Open file descriptor 2...
1651 if ((cg
->stdio_files
[2] = cupsFileOpenFd(2, "w")) != NULL
)
1652 cg
->stdio_files
[2]->is_stdio
= 1;
1655 return (cg
->stdio_files
[2]);
1660 * 'cupsFileStdin()' - Return a CUPS file associated with stdin.
1662 * @since CUPS 1.2/Mac OS X 10.5@
1665 cups_file_t
* /* O - CUPS file */
1668 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1672 * Open file descriptor 0 as needed...
1675 if (!cg
->stdio_files
[0])
1678 * Open file descriptor 0...
1681 if ((cg
->stdio_files
[0] = cupsFileOpenFd(0, "r")) != NULL
)
1682 cg
->stdio_files
[0]->is_stdio
= 1;
1685 return (cg
->stdio_files
[0]);
1690 * 'cupsFileStdout()' - Return a CUPS file associated with stdout.
1692 * @since CUPS 1.2/Mac OS X 10.5@
1695 cups_file_t
* /* O - CUPS file */
1696 cupsFileStdout(void)
1698 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals... */
1702 * Open file descriptor 1 as needed...
1705 if (!cg
->stdio_files
[1])
1708 * Flush any pending output on the stdio file...
1714 * Open file descriptor 1...
1717 if ((cg
->stdio_files
[1] = cupsFileOpenFd(1, "w")) != NULL
)
1718 cg
->stdio_files
[1]->is_stdio
= 1;
1721 return (cg
->stdio_files
[1]);
1726 * 'cupsFileTell()' - Return the current file position.
1728 * @since CUPS 1.2/Mac OS X 10.5@
1731 off_t
/* O - File position */
1732 cupsFileTell(cups_file_t
*fp
) /* I - CUPS file */
1734 DEBUG_printf(("2cupsFileTell(fp=%p)", fp
));
1735 DEBUG_printf(("3cupsFileTell: pos=" CUPS_LLFMT
,
1736 CUPS_LLCAST (fp
? fp
->pos
: -1)));
1738 return (fp
? fp
->pos
: 0);
1743 * 'cupsFileUnlock()' - Unlock access to a file.
1745 * @since CUPS 1.2/Mac OS X 10.5@
1748 int /* O - 0 on success, -1 on error */
1749 cupsFileUnlock(cups_file_t
*fp
) /* I - CUPS file */
1755 DEBUG_printf(("cupsFileUnlock(fp=%p)", fp
));
1757 if (!fp
|| fp
->mode
== 's')
1765 return (locking(fp
->fd
, _LK_UNLCK
, 0));
1767 return (lockf(fp
->fd
, F_ULOCK
, 0));
1773 * 'cupsFileWrite()' - Write to a file.
1775 * @since CUPS 1.2/Mac OS X 10.5@
1778 ssize_t
/* O - Number of bytes written or -1 on error */
1779 cupsFileWrite(cups_file_t
*fp
, /* I - CUPS file */
1780 const char *buf
, /* I - Buffer */
1781 size_t bytes
) /* I - Number of bytes to write */
1784 * Range check input...
1787 DEBUG_printf(("2cupsFileWrite(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")",
1788 fp
, buf
, CUPS_LLCAST bytes
));
1790 if (!fp
|| !buf
|| bytes
< 0 || (fp
->mode
!= 'w' && fp
->mode
!= 's'))
1797 * Write the buffer...
1800 if (fp
->mode
== 's')
1802 if (cups_write(fp
, buf
, bytes
) < 0)
1805 fp
->pos
+= (off_t
)bytes
;
1807 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1809 return ((ssize_t
)bytes
);
1812 if ((fp
->ptr
+ bytes
) > fp
->end
)
1813 if (cupsFileFlush(fp
))
1816 fp
->pos
+= (off_t
)bytes
;
1818 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT
, CUPS_LLCAST fp
->pos
));
1820 if (bytes
> sizeof(fp
->buf
))
1824 return (cups_compress(fp
, buf
, bytes
));
1826 #endif /* HAVE_LIBZ */
1827 return (cups_write(fp
, buf
, bytes
));
1831 memcpy(fp
->ptr
, buf
, bytes
);
1833 return ((ssize_t
)bytes
);
1840 * 'cups_compress()' - Compress a buffer of data...
1843 static ssize_t
/* O - Number of bytes written or -1 */
1844 cups_compress(cups_file_t
*fp
, /* I - CUPS file */
1845 const char *buf
, /* I - Buffer */
1846 size_t bytes
) /* I - Number bytes */
1848 DEBUG_printf(("7cups_compress(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")", fp
, buf
,
1849 CUPS_LLCAST bytes
));
1855 fp
->crc
= crc32(fp
->crc
, (const Bytef
*)buf
, bytes
);
1858 * Deflate the bytes...
1861 fp
->stream
.next_in
= (Bytef
*)buf
;
1862 fp
->stream
.avail_in
= bytes
;
1864 while (fp
->stream
.avail_in
> 0)
1867 * Flush the current buffer...
1870 DEBUG_printf(("9cups_compress: avail_in=%d, avail_out=%d",
1871 fp
->stream
.avail_in
, fp
->stream
.avail_out
));
1873 if (fp
->stream
.avail_out
< (int)(sizeof(fp
->cbuf
) / 8))
1875 if (cups_write(fp
, (char *)fp
->cbuf
, fp
->stream
.next_out
- fp
->cbuf
) < 0)
1878 fp
->stream
.next_out
= fp
->cbuf
;
1879 fp
->stream
.avail_out
= sizeof(fp
->cbuf
);
1882 deflate(&(fp
->stream
), Z_NO_FLUSH
);
1887 #endif /* HAVE_LIBZ */
1891 * 'cups_fill()' - Fill the input buffer...
1894 static ssize_t
/* O - Number of bytes or -1 */
1895 cups_fill(cups_file_t
*fp
) /* I - CUPS file */
1897 ssize_t bytes
; /* Number of bytes read */
1899 int status
; /* Decompression status */
1900 const unsigned char *ptr
, /* Pointer into buffer */
1901 *end
; /* End of buffer */
1902 #endif /* HAVE_LIBZ */
1905 DEBUG_printf(("7cups_fill(fp=%p)", fp
));
1906 DEBUG_printf(("9cups_fill: fp->ptr=%p, fp->end=%p, fp->buf=%p, "
1907 "fp->bufpos=" CUPS_LLFMT
", fp->eof=%d",
1908 fp
->ptr
, fp
->end
, fp
->buf
, CUPS_LLCAST fp
->bufpos
, fp
->eof
));
1910 if (fp
->ptr
&& fp
->end
)
1911 fp
->bufpos
+= fp
->end
- fp
->buf
;
1914 DEBUG_printf(("9cups_fill: fp->compressed=%d", fp
->compressed
));
1916 while (!fp
->ptr
|| fp
->compressed
)
1919 * Check to see if we have read any data yet; if not, see if we have a
1920 * compressed file...
1926 * Reset the file position in case we are seeking...
1932 * Read the first bytes in the file to determine if we have a gzip'd
1936 if ((bytes
= cups_read(fp
, (char *)fp
->buf
, sizeof(fp
->buf
))) < 0)
1939 * Can't read from file!
1942 DEBUG_printf(("9cups_fill: cups_read() returned " CUPS_LLFMT
,
1943 CUPS_LLCAST bytes
));
1948 if (bytes
< 10 || fp
->buf
[0] != 0x1f ||
1949 (fp
->buf
[1] & 255) != 0x8b ||
1950 fp
->buf
[2] != 8 || (fp
->buf
[3] & 0xe0) != 0)
1953 * Not a gzip'd file!
1957 fp
->end
= fp
->buf
+ bytes
;
1959 DEBUG_printf(("9cups_fill: Returning " CUPS_LLFMT
,
1960 CUPS_LLCAST bytes
));
1966 * Parse header junk: extra data, original name, and comment...
1969 ptr
= (unsigned char *)fp
->buf
+ 10;
1970 end
= (unsigned char *)fp
->buf
+ bytes
;
1972 if (fp
->buf
[3] & 0x04)
1975 * Skip extra data...
1978 if ((ptr
+ 2) > end
)
1981 * Can't read from file!
1987 bytes
= ((unsigned char)ptr
[1] << 8) | (unsigned char)ptr
[0];
1993 * Can't read from file!
2000 if (fp
->buf
[3] & 0x08)
2003 * Skip original name data...
2006 while (ptr
< end
&& *ptr
)
2014 * Can't read from file!
2021 if (fp
->buf
[3] & 0x10)
2024 * Skip comment data...
2027 while (ptr
< end
&& *ptr
)
2035 * Can't read from file!
2042 if (fp
->buf
[3] & 0x02)
2045 * Skip header CRC data...
2053 * Can't read from file!
2061 * Copy the flate-compressed data to the compression buffer...
2064 if ((bytes
= end
- ptr
) > 0)
2065 memcpy(fp
->cbuf
, ptr
, bytes
);
2068 * Setup the decompressor data...
2071 fp
->stream
.zalloc
= (alloc_func
)0;
2072 fp
->stream
.zfree
= (free_func
)0;
2073 fp
->stream
.opaque
= (voidpf
)0;
2074 fp
->stream
.next_in
= (Bytef
*)fp
->cbuf
;
2075 fp
->stream
.next_out
= NULL
;
2076 fp
->stream
.avail_in
= bytes
;
2077 fp
->stream
.avail_out
= 0;
2078 fp
->crc
= crc32(0L, Z_NULL
, 0);
2080 if (inflateInit2(&(fp
->stream
), -15) != Z_OK
)
2089 * If we have reached end-of-file, return immediately...
2096 * Fill the decompression buffer as needed...
2099 if (fp
->stream
.avail_in
== 0)
2101 if ((bytes
= cups_read(fp
, (char *)fp
->cbuf
, sizeof(fp
->cbuf
))) <= 0)
2104 fp
->stream
.next_in
= fp
->cbuf
;
2105 fp
->stream
.avail_in
= bytes
;
2109 * Decompress data from the buffer...
2112 fp
->stream
.next_out
= (Bytef
*)fp
->buf
;
2113 fp
->stream
.avail_out
= sizeof(fp
->buf
);
2115 status
= inflate(&(fp
->stream
), Z_NO_FLUSH
);
2117 if (fp
->stream
.next_out
> (Bytef
*)fp
->buf
)
2118 fp
->crc
= crc32(fp
->crc
, (Bytef
*)fp
->buf
,
2119 fp
->stream
.next_out
- (Bytef
*)fp
->buf
);
2121 if (status
== Z_STREAM_END
)
2124 * Read the CRC and length...
2127 unsigned char trailer
[8]; /* Trailer bytes */
2128 uLong tcrc
; /* Trailer CRC */
2131 if (read(fp
->fd
, trailer
, sizeof(trailer
)) < sizeof(trailer
))
2134 * Can't get it, so mark end-of-file...
2141 tcrc
= (((((trailer
[3] << 8) | trailer
[2]) << 8) | trailer
[1]) << 8) |
2144 if (tcrc
!= fp
->crc
)
2147 * Bad CRC, mark end-of-file...
2150 DEBUG_printf(("9cups_fill: tcrc=%08x, fp->crc=%08x",
2151 (unsigned int)tcrc
, (unsigned int)fp
->crc
));
2159 * Otherwise, reset the compressed flag so that we re-read the
2167 bytes
= sizeof(fp
->buf
) - fp
->stream
.avail_out
;
2170 * Return the decompressed data...
2174 fp
->end
= fp
->buf
+ bytes
;
2180 #endif /* HAVE_LIBZ */
2183 * Read a buffer's full of data...
2186 if ((bytes
= cups_read(fp
, fp
->buf
, sizeof(fp
->buf
))) <= 0)
2189 * Can't read from file!
2200 * Return the bytes we read...
2205 fp
->end
= fp
->buf
+ bytes
;
2212 * 'cups_read()' - Read from a file descriptor.
2215 static ssize_t
/* O - Number of bytes read or -1 */
2216 cups_read(cups_file_t
*fp
, /* I - CUPS file */
2217 char *buf
, /* I - Buffer */
2218 size_t bytes
) /* I - Number bytes */
2220 ssize_t total
; /* Total bytes read */
2223 DEBUG_printf(("7cups_read(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")", fp
, buf
,
2224 CUPS_LLCAST bytes
));
2227 * Loop until we read at least 0 bytes...
2233 if (fp
->mode
== 's')
2234 total
= (ssize_t
)recv(fp
->fd
, buf
, (unsigned)bytes
, 0);
2236 total
= (ssize_t
)read(fp
->fd
, buf
, (unsigned)bytes
);
2238 if (fp
->mode
== 's')
2239 total
= recv(fp
->fd
, buf
, bytes
, 0);
2241 total
= read(fp
->fd
, buf
, bytes
);
2244 DEBUG_printf(("9cups_read: total=" CUPS_LLFMT
, CUPS_LLCAST total
));
2250 * Reads can be interrupted by signals and unavailable resources...
2253 if (errno
== EAGAIN
|| errno
== EINTR
)
2260 * Return the total number of bytes read...
2268 * 'cups_write()' - Write to a file descriptor.
2271 static ssize_t
/* O - Number of bytes written or -1 */
2272 cups_write(cups_file_t
*fp
, /* I - CUPS file */
2273 const char *buf
, /* I - Buffer */
2274 size_t bytes
) /* I - Number bytes */
2276 size_t total
; /* Total bytes written */
2277 ssize_t count
; /* Count this time */
2280 DEBUG_printf(("7cups_write(fp=%p, buf=%p, bytes=" CUPS_LLFMT
")", fp
, buf
,
2281 CUPS_LLCAST bytes
));
2284 * Loop until all bytes are written...
2291 if (fp
->mode
== 's')
2292 count
= (ssize_t
)send(fp
->fd
, buf
, (unsigned)bytes
, 0);
2294 count
= (ssize_t
)write(fp
->fd
, buf
, (unsigned)bytes
);
2296 if (fp
->mode
== 's')
2297 count
= send(fp
->fd
, buf
, bytes
, 0);
2299 count
= write(fp
->fd
, buf
, bytes
);
2302 DEBUG_printf(("9cups_write: count=" CUPS_LLFMT
, CUPS_LLCAST count
));
2307 * Writes can be interrupted by signals and unavailable resources...
2310 if (errno
== EAGAIN
|| errno
== EINTR
)
2317 * Update the counts for the last write call...
2326 * Return the total number of bytes written...
2329 return ((ssize_t
)total
);
2334 * End of "$Id: file.c 7672 2008-06-18 22:03:02Z mike $".