summaryrefslogtreecommitdiff
path: root/cups/file.c
diff options
context:
space:
mode:
authorjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2007-02-14 19:18:46 +0000
committerjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2007-02-14 19:18:46 +0000
commitb86bc4cf571c35972a94a634ea884baff9799fa9 (patch)
tree9337cdf0bf4a63518307072ab0c75ce665c8a20a /cups/file.c
parent411affcf6ae840dbe82786a1f42c16cb3127d20f (diff)
downloadcups-b86bc4cf571c35972a94a634ea884baff9799fa9.tar.gz
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@266 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/file.c')
-rw-r--r--cups/file.c85
1 files changed, 65 insertions, 20 deletions
diff --git a/cups/file.c b/cups/file.c
index f4bbf34e0..b2a831157 100644
--- a/cups/file.c
+++ b/cups/file.c
@@ -1,5 +1,5 @@
/*
- * "$Id: file.c 5993 2006-09-29 12:57:31Z mike $"
+ * "$Id: file.c 6193 2007-01-10 19:27:04Z mike $"
*
* File functions for the Common UNIX Printing System (CUPS).
*
@@ -8,7 +8,7 @@
* our own file functions allows us to provide transparent support of
* gzip'd print files, PPD files, etc.
*
- * Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ * Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
@@ -95,6 +95,16 @@
/*
+ * Some operating systems don't define O_BINARY, which is used by Microsoft
+ * and IBM to flag binary files...
+ */
+
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif /* !O_BINARY */
+
+
+/*
* Types and structures...
*/
@@ -332,7 +342,11 @@ cupsFileFind(const char *filename, /* I - File to find */
while (*path)
{
+#ifdef WIN32
+ if (*path == ';' || (*path == ':' && ((bufptr - buffer) > 1 || !isalpha(buffer[0] & 255))))
+#else
if (*path == ';' || *path == ':')
+#endif /* WIN32 */
{
if (bufptr > buffer && bufptr[-1] != '/' && bufptr < bufend)
*bufptr++ = '/';
@@ -344,7 +358,10 @@ cupsFileFind(const char *filename, /* I - File to find */
#else
if (!access(buffer, executable ? X_OK : 0))
#endif /* WIN32 */
+ {
+ DEBUG_printf(("cupsFileFind: Returning \"%s\"\n", buffer));
return (buffer);
+ }
bufptr = buffer;
}
@@ -364,9 +381,15 @@ cupsFileFind(const char *filename, /* I - File to find */
strlcpy(bufptr, filename, bufend - bufptr);
if (!access(buffer, 0))
+ {
+ DEBUG_printf(("cupsFileFind: Returning \"%s\"\n", buffer));
return (buffer);
+ }
else
+ {
+ DEBUG_puts("cupsFileFind: Returning NULL");
return (NULL);
+ }
}
@@ -392,7 +415,7 @@ cupsFileFlush(cups_file_t *fp) /* I - CUPS file */
return (-1);
}
- bytes = fp->ptr - fp->buf;
+ bytes = (ssize_t)(fp->ptr - fp->buf);
DEBUG_printf((" Flushing %ld bytes...\n", (long)bytes));
@@ -427,7 +450,10 @@ cupsFileGetChar(cups_file_t *fp) /* I - CUPS file */
*/
if (!fp || (fp->mode != 'r' && fp->mode != 's'))
+ {
+ DEBUG_puts("cupsFileGetChar: Bad arguments!");
return (-1);
+ }
/*
* If the input buffer is empty, try to read more data...
@@ -435,12 +461,17 @@ cupsFileGetChar(cups_file_t *fp) /* I - CUPS file */
if (fp->ptr >= fp->end)
if (cups_fill(fp) < 0)
+ {
+ DEBUG_puts("cupsFileGetChar: Unable to fill buffer!");
return (-1);
+ }
/*
* Return the next character in the buffer...
*/
+ DEBUG_printf(("cupsFileGetChar: Returning %d...\n", *(fp->ptr) & 255));
+
return (*(fp->ptr)++ & 255);
}
@@ -780,15 +811,15 @@ cupsFileOpen(const char *filename, /* I - Name of file */
switch (*mode)
{
case 'a' : /* Append file */
- fd = open(filename, O_RDWR | O_CREAT | O_APPEND | O_LARGEFILE, 0666);
+ fd = open(filename, O_RDWR | O_CREAT | O_APPEND | O_LARGEFILE | O_BINARY, 0666);
break;
case 'r' : /* Read file */
- fd = open(filename, O_RDONLY | O_LARGEFILE, 0);
+ fd = open(filename, O_RDONLY | O_LARGEFILE | O_BINARY, 0);
break;
case 'w' : /* Write file */
- fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT | O_LARGEFILE, 0666);
+ fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT | O_LARGEFILE | O_BINARY, 0666);
break;
case 's' : /* Read/write socket */
@@ -1104,7 +1135,7 @@ cupsFilePuts(cups_file_t *fp, /* I - CUPS file */
* Write the string...
*/
- bytes = strlen(s);
+ bytes = (int)strlen(s);
if (fp->mode == 's')
{
@@ -1179,14 +1210,14 @@ cupsFileRead(cups_file_t *fp, /* I - CUPS file */
DEBUG_printf((" cups_fill() returned -1, total=%d\n", total));
if (total > 0)
- return (total);
+ return ((ssize_t)total);
else
return (-1);
}
- count = fp->end - fp->ptr;
- if (count > bytes)
- count = bytes;
+ count = (ssize_t)(fp->end - fp->ptr);
+ if (count > (ssize_t)bytes)
+ count = (ssize_t)bytes;
memcpy(buf, fp->ptr, count);
fp->ptr += count;
@@ -1206,7 +1237,7 @@ cupsFileRead(cups_file_t *fp, /* I - CUPS file */
DEBUG_printf((" total=%d\n", total));
- return (total);
+ return ((ssize_t)total);
}
@@ -1328,7 +1359,7 @@ cupsFileSeek(cups_file_t *fp, /* I - CUPS file */
*/
if (fp->ptr)
- bytes = fp->end - fp->buf;
+ bytes = (ssize_t)(fp->end - fp->buf);
else
bytes = 0;
@@ -1582,16 +1613,16 @@ cupsFileWrite(cups_file_t *fp, /* I - CUPS file */
if (cups_write(fp, buf, bytes) < 0)
return (-1);
- fp->pos += bytes;
+ fp->pos += (off_t)bytes;
- return (bytes);
+ return ((ssize_t)bytes);
}
if ((fp->ptr + bytes) > fp->end)
if (cupsFileFlush(fp))
return (-1);
- fp->pos += bytes;
+ fp->pos += (off_t)bytes;
if (bytes > sizeof(fp->buf))
{
@@ -1606,7 +1637,7 @@ cupsFileWrite(cups_file_t *fp, /* I - CUPS file */
{
memcpy(fp->ptr, buf, bytes);
fp->ptr += bytes;
- return (bytes);
+ return ((ssize_t)bytes);
}
}
@@ -1687,7 +1718,7 @@ cups_fill(cups_file_t *fp) /* I - CUPS file */
*/
if (fp->ptr && fp->end)
- fp->pos += fp->end - fp->buf;
+ fp->pos += (off_t)(fp->end - fp->buf);
#ifdef HAVE_LIBZ
DEBUG_printf((" fp->compressed=%d\n", fp->compressed));
@@ -1995,10 +2026,17 @@ cups_read(cups_file_t *fp, /* I - CUPS file */
for (;;)
{
+#ifdef WIN32
+ if (fp->mode == 's')
+ total = (ssize_t)recv(fp->fd, buf, (unsigned)bytes, 0);
+ else
+ total = (ssize_t)read(fp->fd, buf, (unsigned)bytes);
+#else
if (fp->mode == 's')
total = recv(fp->fd, buf, bytes, 0);
else
total = read(fp->fd, buf, bytes);
+#endif /* WIN32 */
if (total >= 0)
break;
@@ -2044,10 +2082,17 @@ cups_write(cups_file_t *fp, /* I - CUPS file */
total = 0;
while (bytes > 0)
{
+#ifdef WIN32
+ if (fp->mode == 's')
+ count = (ssize_t)send(fp->fd, buf, (unsigned)bytes, 0);
+ else
+ count = (ssize_t)write(fp->fd, buf, (unsigned)bytes);
+#else
if (fp->mode == 's')
count = send(fp->fd, buf, bytes, 0);
else
count = write(fp->fd, buf, bytes);
+#endif /* WIN32 */
if (count < 0)
{
@@ -2076,10 +2121,10 @@ cups_write(cups_file_t *fp, /* I - CUPS file */
* Return the total number of bytes written...
*/
- return (total);
+ return ((ssize_t)total);
}
/*
- * End of "$Id: file.c 5993 2006-09-29 12:57:31Z mike $".
+ * End of "$Id: file.c 6193 2007-01-10 19:27:04Z mike $".
*/