#
-# "$Id: Makefile,v 1.52 2001/03/02 13:42:19 mike Exp $"
+# "$Id: Makefile,v 1.53 2001/03/09 20:06:06 mike Exp $"
#
# Support library Makefile for the Common UNIX Printing System (CUPS).
#
# Object files...
#
-LIBOBJS = dest.o emit.o http.o ipp.o language.o mark.o md5.o md5passwd.o \
- options.o page.o ppd.o snprintf.o string.o usersys.o util.o
+LIBOBJS = dest.o emit.o encode.o http.o ipp.o language.o mark.o md5.o \
+ md5passwd.o options.o page.o ppd.o snprintf.o string.o \
+ tempfile.o usersys.o util.o
OBJS = $(LIBOBJS) testhttp.o testppd.o
dest.o: cups.h http.h ipp.h language.h string.h
emit.o: ppd.h
+encode.o: cups.h ipp.h string.h
http.o: http.h ipp.h md5.h string.h
ipp.o: http.h ipp.h string.h language.h
language.o: cups_C.h language.h string.h
ppd.o: language.h ppd.h
snprintf.o: string.h
string.o: string.h
+tempfile.o: cups.h string.h
usersys.o: cups.h
util.o: cups.h http.h ipp.h
#
-# End of "$Id: Makefile,v 1.52 2001/03/02 13:42:19 mike Exp $".
+# End of "$Id: Makefile,v 1.53 2001/03/09 20:06:06 mike Exp $".
#
--- /dev/null
+/*
+ * "$Id: encode.c,v 1.1 2001/03/09 20:06:06 mike Exp $"
+ *
+ * Option encoding routines for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2001 by Easy Software Products.
+ *
+ * These coded instructions, statements, and computer programs are the
+ * property of Easy Software Products and are protected by Federal
+ * copyright law. Distribution and use rights are outlined in the file
+ * "LICENSE.txt" which should have been included with this file. If this
+ * file is missing or damaged please contact Easy Software Products
+ * at:
+ *
+ * Attn: CUPS Licensing Information
+ * Easy Software Products
+ * 44141 Airport View Drive, Suite 204
+ * Hollywood, Maryland 20636-3111 USA
+ *
+ * Voice: (301) 373-9603
+ * EMail: cups-info@cups.org
+ * WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ * cupsEncodeOptions() - Encode printer options into IPP attributes.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cups.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include "string.h"
+#include "debug.h"
+
+
+/*
+ * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
+ */
+
+void
+cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */
+ int num_options, /* I - Number of options */
+ cups_option_t *options) /* I - Options */
+{
+ int i, j; /* Looping vars */
+ int count; /* Number of values */
+ int n; /* Attribute value */
+ char *s, /* Pointer into option value */
+ *val, /* Pointer to option value */
+ *copy, /* Copy of option value */
+ *sep; /* Option separator */
+ ipp_attribute_t *attr; /* IPP job-id attribute */
+
+
+ DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)\n", ipp, num_options, options));
+
+ if (ipp == NULL || num_options < 1 || options == NULL)
+ return;
+
+ /*
+ * Handle the document format stuff first...
+ */
+
+ if ((val = (char *)cupsGetOption("document-format", num_options, options)) != NULL)
+ ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
+ NULL, val);
+ else if (cupsGetOption("raw", num_options, options))
+ ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
+ NULL, "application/vnd.cups-raw");
+ else
+ ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
+ NULL, "application/octet-stream");
+
+ /*
+ * Then add all other options...
+ */
+
+ for (i = 0; i < num_options; i ++)
+ {
+ /*
+ * Skip document format options - handled above...
+ */
+
+ if (strcasecmp(options[i].name, "raw") == 0 ||
+ strcasecmp(options[i].name, "document-format") == 0)
+ continue;
+
+ /*
+ * Count the number of values...
+ */
+
+ for (count = 1, sep = options[i].value;
+ (sep = strchr(sep + 1, ',')) != NULL;
+ count ++);
+
+ DEBUG_printf(("cupsEncodeOptions: option = \'%s\', count = %d\n",
+ options[i].name, count));
+
+ if ((attr = _ipp_add_attr(ipp, count)) == NULL)
+ {
+ /*
+ * Ran out of memory!
+ */
+
+ DEBUG_puts("cupsEncodeOptions: Ran out of memory for attributes!");
+ return;
+ }
+
+ attr->group_tag = IPP_TAG_JOB;
+
+ if ((attr->name = strdup(options[i].name)) == NULL)
+ {
+ /*
+ * Ran out of memory!
+ */
+
+ DEBUG_puts("cupsEncodeOptions: Ran out of memory for name!");
+ return;
+ }
+
+ if (count > 1)
+ {
+ /*
+ * Make a copy of the value we can fiddle with...
+ */
+
+ if ((copy = strdup(options[i].value)) == NULL)
+ {
+ /*
+ * Ran out of memory!
+ */
+
+ DEBUG_puts("cupsEncodeOptions: Ran out of memory for value copy!");
+ return;
+ }
+
+ val = copy;
+ }
+ else
+ {
+ /*
+ * Since we have a single value, use the value directly...
+ */
+
+ val = options[i].value;
+ copy = NULL;
+ }
+
+ /*
+ * See what the option value is; for compatibility with older interface
+ * scripts, we have to support single-argument options as well as
+ * option=value, option=low-high, option=MxN, and option=val1,val2,...,valN.
+ */
+
+ if (*val == '\0')
+ {
+ /*
+ * Old-style System V boolean value...
+ */
+
+ attr->value_tag = IPP_TAG_BOOLEAN;
+
+ if (strncasecmp(attr->name, "no", 2) == 0)
+ {
+ DEBUG_puts("cupsEncodeOptions: Added boolean false value...");
+ strcpy(attr->name, attr->name + 2);
+ attr->values[0].boolean = 0;
+ }
+ else
+ {
+ DEBUG_puts("cupsEncodeOptions: Added boolean true value...");
+ attr->values[0].boolean = 1;
+ }
+ }
+ else
+ {
+ /*
+ * Scan the value string for values...
+ */
+
+ for (j = 0; *val != '\0'; val = sep, j ++)
+ {
+ /*
+ * Find the end of this value and mark it if needed...
+ */
+
+ if ((sep = strchr(val, ',')) != NULL)
+ *sep++ = '\0';
+ else
+ sep = val + strlen(val);
+
+ /*
+ * See what kind of value it is...
+ */
+
+ if (strcasecmp(val, "true") == 0 ||
+ strcasecmp(val, "on") == 0 ||
+ strcasecmp(val, "yes") == 0)
+ {
+ /*
+ * Boolean value - true...
+ */
+
+ attr->value_tag = IPP_TAG_BOOLEAN;
+ attr->values[j].boolean = 1;
+
+ DEBUG_puts("cupsEncodeOptions: Added boolean true value...");
+ }
+ else if (strcasecmp(val, "false") == 0 ||
+ strcasecmp(val, "off") == 0 ||
+ strcasecmp(val, "no") == 0)
+ {
+ /*
+ * Boolean value - false...
+ */
+
+ attr->value_tag = IPP_TAG_BOOLEAN;
+ attr->values[j].boolean = 0;
+
+ DEBUG_puts("cupsEncodeOptions: Added boolean false value...");
+ }
+ else
+ {
+ /*
+ * Number, range, resolution, or string...
+ */
+
+ n = strtol(val, &s, 0);
+
+ if (*s != '\0' && *s != '-' && (*s != 'x' || s == val))
+ {
+ /*
+ * String value(s)...
+ */
+
+ if ((attr->values[j].string.text = strdup(val)) == NULL)
+ {
+ /*
+ * Ran out of memory!
+ */
+
+ DEBUG_puts("cupsEncodeOptions: Ran out of memory for string!");
+ return;
+ }
+
+ attr->value_tag = IPP_TAG_NAME;
+
+ DEBUG_printf(("cupsEncodeOptions: Added string value \'%s\'...\n", val));
+ }
+ else if (*s == '-')
+ {
+ attr->value_tag = IPP_TAG_RANGE;
+ attr->values[j].range.lower = n;
+ attr->values[j].range.upper = strtol(s + 1, NULL, 0);
+
+ DEBUG_printf(("cupsEncodeOptions: Added range option value %d-%d...\n",
+ n, attr->values[j].range.upper));
+ }
+ else if (*s == 'x')
+ {
+ attr->value_tag = IPP_TAG_RESOLUTION;
+ attr->values[j].resolution.xres = n;
+ attr->values[j].resolution.yres = strtol(s + 1, &s, 0);
+
+ if (strcasecmp(s, "dpc") == 0)
+ attr->values[j].resolution.units = IPP_RES_PER_CM;
+ else if (strcasecmp(s, "dpi") == 0)
+ attr->values[j].resolution.units = IPP_RES_PER_INCH;
+ else
+ {
+ if ((attr->values[j].string.text = strdup(val)) == NULL)
+ {
+ /*
+ * Ran out of memory!
+ */
+
+ DEBUG_puts("cupsEncodeOptions: Ran out of memory for string!");
+ return;
+ }
+
+ attr->value_tag = IPP_TAG_NAME;
+
+ DEBUG_printf(("cupsEncodeOptions: Added string value \'%s\'...\n", val));
+ continue;
+ }
+
+ DEBUG_printf(("cupsEncodeOptions: Adding resolution option value %s...\n",
+ val));
+ }
+ else
+ {
+ attr->value_tag = IPP_TAG_INTEGER;
+ attr->values[j].integer = n;
+
+ DEBUG_printf(("cupsEncodeOptions: Adding integer option value %d...\n", n));
+ }
+ }
+ }
+ }
+ }
+}
+
+
+/*
+ * End of "$Id: encode.c,v 1.1 2001/03/09 20:06:06 mike Exp $".
+ */
/*
- * "$Id: options.c,v 1.20 2001/03/07 16:54:20 mike Exp $"
+ * "$Id: options.c,v 1.21 2001/03/09 20:06:07 mike Exp $"
*
* Option routines for the Common UNIX Printing System (CUPS).
*
*
* Contents:
*
- * cupsAddOption() - Add an option to an option array.
- * cupsEncodeOptions() - Encode printer options into IPP attributes.
- * cupsFreeOptions() - Free all memory used by options.
- * cupsGetOption() - Get an option value.
- * cupsParseOptions() - Parse options from a command-line argument.
- * cupsMarkOptions() - Mark command-line options in a PPD file.
+ * cupsAddOption() - Add an option to an option array.
+ * cupsFreeOptions() - Free all memory used by options.
+ * cupsGetOption() - Get an option value.
+ * cupsParseOptions() - Parse options from a command-line argument.
+ * cupsMarkOptions() - Mark command-line options in a PPD file.
*/
/*
}
-/*
- * 'cupsEncodeOptions()' - Encode printer options into IPP attributes.
- */
-
-void
-cupsEncodeOptions(ipp_t *ipp, /* I - Request to add to */
- int num_options, /* I - Number of options */
- cups_option_t *options) /* I - Options */
-{
- int i, j; /* Looping vars */
- int count; /* Number of values */
- int n; /* Attribute value */
- char *s, /* Pointer into option value */
- *val, /* Pointer to option value */
- *copy, /* Copy of option value */
- *sep; /* Option separator */
- ipp_attribute_t *attr; /* IPP job-id attribute */
-
-
- DEBUG_printf(("cupsEncodeOptions(%p, %d, %p)\n", ipp, num_options, options));
-
- if (ipp == NULL || num_options < 1 || options == NULL)
- return;
-
- /*
- * Handle the document format stuff first...
- */
-
- if ((val = (char *)cupsGetOption("document-format", num_options, options)) != NULL)
- ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
- NULL, val);
- else if (cupsGetOption("raw", num_options, options))
- ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
- NULL, "application/vnd.cups-raw");
- else
- ippAddString(ipp, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format",
- NULL, "application/octet-stream");
-
- /*
- * Then add all other options...
- */
-
- for (i = 0; i < num_options; i ++)
- {
- /*
- * Skip document format options - handled above...
- */
-
- if (strcasecmp(options[i].name, "raw") == 0 ||
- strcasecmp(options[i].name, "document-format") == 0)
- continue;
-
- /*
- * Count the number of values...
- */
-
- for (count = 1, sep = options[i].value;
- (sep = strchr(sep + 1, ',')) != NULL;
- count ++);
-
- DEBUG_printf(("cupsEncodeOptions: option = \'%s\', count = %d\n",
- options[i].name, count));
-
- if ((attr = _ipp_add_attr(ipp, count)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions: Ran out of memory for attributes!");
- return;
- }
-
- attr->group_tag = IPP_TAG_JOB;
-
- if ((attr->name = strdup(options[i].name)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions: Ran out of memory for name!");
- return;
- }
-
- if (count > 1)
- {
- /*
- * Make a copy of the value we can fiddle with...
- */
-
- if ((copy = strdup(options[i].value)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions: Ran out of memory for value copy!");
- return;
- }
-
- val = copy;
- }
- else
- {
- /*
- * Since we have a single value, use the value directly...
- */
-
- val = options[i].value;
- copy = NULL;
- }
-
- /*
- * See what the option value is; for compatibility with older interface
- * scripts, we have to support single-argument options as well as
- * option=value, option=low-high, option=MxN, and option=val1,val2,...,valN.
- */
-
- if (*val == '\0')
- {
- /*
- * Old-style System V boolean value...
- */
-
- attr->value_tag = IPP_TAG_BOOLEAN;
-
- if (strncasecmp(attr->name, "no", 2) == 0)
- {
- DEBUG_puts("cupsEncodeOptions: Added boolean false value...");
- strcpy(attr->name, attr->name + 2);
- attr->values[0].boolean = 0;
- }
- else
- {
- DEBUG_puts("cupsEncodeOptions: Added boolean true value...");
- attr->values[0].boolean = 1;
- }
- }
- else
- {
- /*
- * Scan the value string for values...
- */
-
- for (j = 0; *val != '\0'; val = sep, j ++)
- {
- /*
- * Find the end of this value and mark it if needed...
- */
-
- if ((sep = strchr(val, ',')) != NULL)
- *sep++ = '\0';
- else
- sep = val + strlen(val);
-
- /*
- * See what kind of value it is...
- */
-
- if (strcasecmp(val, "true") == 0 ||
- strcasecmp(val, "on") == 0 ||
- strcasecmp(val, "yes") == 0)
- {
- /*
- * Boolean value - true...
- */
-
- attr->value_tag = IPP_TAG_BOOLEAN;
- attr->values[j].boolean = 1;
-
- DEBUG_puts("cupsEncodeOptions: Added boolean true value...");
- }
- else if (strcasecmp(val, "false") == 0 ||
- strcasecmp(val, "off") == 0 ||
- strcasecmp(val, "no") == 0)
- {
- /*
- * Boolean value - false...
- */
-
- attr->value_tag = IPP_TAG_BOOLEAN;
- attr->values[j].boolean = 0;
-
- DEBUG_puts("cupsEncodeOptions: Added boolean false value...");
- }
- else
- {
- /*
- * Number, range, resolution, or string...
- */
-
- n = strtol(val, &s, 0);
-
- if (*s != '\0' && *s != '-' && (*s != 'x' || s == val))
- {
- /*
- * String value(s)...
- */
-
- if ((attr->values[j].string.text = strdup(val)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions: Ran out of memory for string!");
- return;
- }
-
- attr->value_tag = IPP_TAG_NAME;
-
- DEBUG_printf(("cupsEncodeOptions: Added string value \'%s\'...\n", val));
- }
- else if (*s == '-')
- {
- attr->value_tag = IPP_TAG_RANGE;
- attr->values[j].range.lower = n;
- attr->values[j].range.upper = strtol(s + 1, NULL, 0);
-
- DEBUG_printf(("cupsEncodeOptions: Added range option value %d-%d...\n",
- n, attr->values[j].range.upper));
- }
- else if (*s == 'x')
- {
- attr->value_tag = IPP_TAG_RESOLUTION;
- attr->values[j].resolution.xres = n;
- attr->values[j].resolution.yres = strtol(s + 1, &s, 0);
-
- if (strcasecmp(s, "dpc") == 0)
- attr->values[j].resolution.units = IPP_RES_PER_CM;
- else if (strcasecmp(s, "dpi") == 0)
- attr->values[j].resolution.units = IPP_RES_PER_INCH;
- else
- {
- if ((attr->values[j].string.text = strdup(val)) == NULL)
- {
- /*
- * Ran out of memory!
- */
-
- DEBUG_puts("cupsEncodeOptions: Ran out of memory for string!");
- return;
- }
-
- attr->value_tag = IPP_TAG_NAME;
-
- DEBUG_printf(("cupsEncodeOptions: Added string value \'%s\'...\n", val));
- continue;
- }
-
- DEBUG_printf(("cupsEncodeOptions: Adding resolution option value %s...\n",
- val));
- }
- else
- {
- attr->value_tag = IPP_TAG_INTEGER;
- attr->values[j].integer = n;
-
- DEBUG_printf(("cupsEncodeOptions: Adding integer option value %d...\n", n));
- }
- }
- }
- }
- }
-}
-
-
/*
* 'cupsFreeOptions()' - Free all memory used by options.
*/
/*
- * End of "$Id: options.c,v 1.20 2001/03/07 16:54:20 mike Exp $".
+ * End of "$Id: options.c,v 1.21 2001/03/09 20:06:07 mike Exp $".
*/
--- /dev/null
+/*
+ * "$Id: tempfile.c,v 1.1 2001/03/09 20:06:07 mike Exp $"
+ *
+ * Temp file utilities for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2001 by Easy Software Products.
+ *
+ * These coded instructions, statements, and computer programs are the
+ * property of Easy Software Products and are protected by Federal
+ * copyright law. Distribution and use rights are outlined in the file
+ * "LICENSE.txt" which should have been included with this file. If this
+ * file is missing or damaged please contact Easy Software Products
+ * at:
+ *
+ * Attn: CUPS Licensing Information
+ * Easy Software Products
+ * 44141 Airport View Drive, Suite 204
+ * Hollywood, Maryland 20636-3111 USA
+ *
+ * Voice: (301) 373-9603
+ * EMail: cups-info@cups.org
+ * WWW: http://www.cups.org
+ *
+ * Contents:
+ *
+ * cupsTempFd() - Create a temporary file.
+ * cupsTempFile() - Generate a temporary filename.
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cups.h"
+#include "string.h"
+#include "debug.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#if defined(WIN32) || defined(__EMX__)
+# include <io.h>
+#else
+# include <unistd.h>
+#endif /* WIN32 || __EMX__ */
+
+
+/*
+ * 'cupsTempFd()' - Create a temporary file.
+ */
+
+int /* O - New file descriptor */
+cupsTempFd(char *filename, /* I - Pointer to buffer */
+ int len) /* I - Size of buffer */
+{
+ int fd; /* File descriptor for temp file */
+#ifdef WIN32
+ char tmpdir[1024]; /* Windows temporary directory */
+ DWORD curtime; /* Current time */
+#else
+ char *tmpdir; /* TMPDIR environment var */
+ struct timeval curtime; /* Current time */
+#endif /* WIN32 */
+ static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
+
+
+ /*
+ * See if a filename was specified...
+ */
+
+ if (filename == NULL)
+ {
+ filename = buf;
+ len = sizeof(buf);
+ }
+
+ /*
+ * See if TMPDIR is defined...
+ */
+
+#ifdef WIN32
+ GetTempPath(sizeof(tmpdir), tmpdir);
+#else
+ if ((tmpdir = getenv("TMPDIR")) == NULL)
+ {
+ /*
+ * Put root temp files in restricted temp directory...
+ */
+
+ if (getuid() == 0)
+ tmpdir = CUPS_REQUESTS "/tmp";
+ else
+ tmpdir = "/var/tmp";
+ }
+#endif /* WIN32 */
+
+ /*
+ * Make the temporary name using the specified directory...
+ */
+
+ do
+ {
+#ifdef WIN32
+ /*
+ * Get the current time of day...
+ */
+
+ curtime = GetTickCount();
+
+ /*
+ * Format a string using the hex time values...
+ */
+
+ snprintf(filename, len - 1, "%s/%08lx", tmpdir, curtime);
+#else
+ /*
+ * Get the current time of day...
+ */
+
+ gettimeofday(&curtime, NULL);
+
+ /*
+ * Format a string using the hex time values...
+ */
+
+ snprintf(filename, len - 1, "%s/%08lx%05lx", tmpdir,
+ curtime.tv_sec, curtime.tv_usec);
+#endif /* WIN32 */
+
+ /*
+ * Open the file in "exclusive" mode, making sure that we don't
+ * stomp on an existing file or someone's symlink crack...
+ */
+
+#ifdef O_NOFOLLOW
+ fd = open(filename, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
+#else
+ fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
+#endif /* O_NOFOLLOW */
+
+ if (fd < 0 && errno == EPERM)
+ break; /* Stop immediately if permission denied! */
+ }
+ while (fd < 0);
+
+ /*
+ * Return the file descriptor...
+ */
+
+ return (fd);
+}
+
+
+/*
+ * 'cupsTempFile()' - Generate a temporary filename.
+ */
+
+char * /* O - Filename */
+cupsTempFile(char *filename, /* I - Pointer to buffer */
+ int len) /* I - Size of buffer */
+{
+ int fd; /* File descriptor for temp file */
+ static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
+
+
+ /*
+ * See if a filename was specified...
+ */
+
+ if (filename == NULL)
+ {
+ filename = buf;
+ len = sizeof(buf);
+ }
+
+ /*
+ * Create the temporary file...
+ */
+
+ if ((fd = cupsTempFd(filename, len)) < 0)
+ return (NULL);
+
+ /*
+ * Close the temp file - it'll be reopened later as needed...
+ */
+
+ close(fd);
+
+ /*
+ * Return the temp filename...
+ */
+
+ return (filename);
+}
+
+
+/*
+ * End of "$Id: tempfile.c,v 1.1 2001/03/09 20:06:07 mike Exp $".
+ */
/*
- * "$Id: util.c,v 1.80 2001/03/02 14:30:14 mike Exp $"
+ * "$Id: util.c,v 1.81 2001/03/09 20:06:07 mike Exp $"
*
* Printing utilities for the Common UNIX Printing System (CUPS).
*
* cupsLastError() - Return the last IPP error that occurred.
* cupsPrintFile() - Print a file to a printer or class.
* cupsPrintFiles() - Print one or more files to a printer or class.
- * cupsTempFd() - Create a temporary file.
- * cupsTempFile() - Generate a temporary filename.
* cups_connect() - Connect to the specified host...
* cups_local_auth() - Get the local authorization certificate if
* available/applicable...
}
-/*
- * 'cupsTempFd()' - Create a temporary file.
- */
-
-int /* O - New file descriptor */
-cupsTempFd(char *filename, /* I - Pointer to buffer */
- int len) /* I - Size of buffer */
-{
- int fd; /* File descriptor for temp file */
-#ifdef WIN32
- char tmpdir[1024]; /* Windows temporary directory */
- DWORD curtime; /* Current time */
-#else
- char *tmpdir; /* TMPDIR environment var */
- struct timeval curtime; /* Current time */
-#endif /* WIN32 */
- static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
-
-
- /*
- * See if a filename was specified...
- */
-
- if (filename == NULL)
- {
- filename = buf;
- len = sizeof(buf);
- }
-
- /*
- * See if TMPDIR is defined...
- */
-
-#ifdef WIN32
- GetTempPath(sizeof(tmpdir), tmpdir);
-#else
- if ((tmpdir = getenv("TMPDIR")) == NULL)
- {
- /*
- * Put root temp files in restricted temp directory...
- */
-
- if (getuid() == 0)
- tmpdir = CUPS_REQUESTS "/tmp";
- else
- tmpdir = "/var/tmp";
- }
-#endif /* WIN32 */
-
- /*
- * Make the temporary name using the specified directory...
- */
-
- do
- {
-#ifdef WIN32
- /*
- * Get the current time of day...
- */
-
- curtime = GetTickCount();
-
- /*
- * Format a string using the hex time values...
- */
-
- snprintf(filename, len - 1, "%s/%08lx", tmpdir, curtime);
-#else
- /*
- * Get the current time of day...
- */
-
- gettimeofday(&curtime, NULL);
-
- /*
- * Format a string using the hex time values...
- */
-
- snprintf(filename, len - 1, "%s/%08lx%05lx", tmpdir,
- curtime.tv_sec, curtime.tv_usec);
-#endif /* WIN32 */
-
- /*
- * Open the file in "exclusive" mode, making sure that we don't
- * stomp on an existing file or someone's symlink crack...
- */
-
-#ifdef O_NOFOLLOW
- fd = open(filename, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
-#else
- fd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-#endif /* O_NOFOLLOW */
-
- if (fd < 0 && errno == EPERM)
- break; /* Stop immediately if permission denied! */
- }
- while (fd < 0);
-
- /*
- * Return the file descriptor...
- */
-
- return (fd);
-}
-
-
-/*
- * 'cupsTempFile()' - Generate a temporary filename.
- */
-
-char * /* O - Filename */
-cupsTempFile(char *filename, /* I - Pointer to buffer */
- int len) /* I - Size of buffer */
-{
- int fd; /* File descriptor for temp file */
- static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
-
-
- /*
- * See if a filename was specified...
- */
-
- if (filename == NULL)
- {
- filename = buf;
- len = sizeof(buf);
- }
-
- /*
- * Create the temporary file...
- */
-
- if ((fd = cupsTempFd(filename, len)) < 0)
- return (NULL);
-
- /*
- * Close the temp file - it'll be reopened later as needed...
- */
-
- close(fd);
-
- /*
- * Return the temp filename...
- */
-
- return (filename);
-}
-
-
/*
* 'cups_connect()' - Connect to the specified host...
*/
/*
- * End of "$Id: util.c,v 1.80 2001/03/02 14:30:14 mike Exp $".
+ * End of "$Id: util.c,v 1.81 2001/03/09 20:06:07 mike Exp $".
*/