]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/tempfile.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / tempfile.c
index 0e64565b09d11d6b73f6ea7364541d94ccf039a6..75c95d6fbf687efd341a2384cd8aa0b9df5aff4b 100644 (file)
@@ -1,43 +1,32 @@
 /*
- * "$Id: tempfile.c 4918 2006-01-12 05:14:40Z mike $"
+ * "$Id$"
  *
- *   Temp file utilities for the Common UNIX Printing System (CUPS).
+ *   Temp file utilities for CUPS.
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 2007-2012 by Apple Inc.
+ *   Copyright 1997-2006 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 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. 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
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
  * Contents:
  *
- *   cupsTempFd()    - Create a temporary file.
- *   cupsTempFile()  - Generate a temporary filename.
- *   cupsTempFile2() - Create a temporary CUPS file.
+ *   cupsTempFd()    - Creates a temporary file.
+ *   cupsTempFile()  - Generates a temporary filename.
+ *   cupsTempFile2() - Creates a temporary CUPS file.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include "globals.h"
-#include "debug.h"
+#include "cups-private.h"
 #include <stdlib.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #if defined(WIN32) || defined(__EMX__)
 
 
 /*
- * 'cupsTempFd()' - Create a temporary file.
+ * 'cupsTempFd()' - Creates a temporary file.
  *
- * The temporary filename is stored in the filename buffer.
+ * The temporary filename is returned in the filename buffer.
+ * The temporary file is opened for reading and writing.
  */
 
-int                                    /* O - New file descriptor */
+int                                    /* O - New file descriptor or -1 on error */
 cupsTempFd(char *filename,             /* I - Pointer to buffer */
            int  len)                   /* I - Size of buffer */
 {
@@ -79,17 +69,19 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
     tmpdir = tmppath;
   }
 #else
-  if ((tmpdir = getenv("TMPDIR")) == NULL)
-  {
-   /*
-    * Put root temp files in restricted temp directory...
-    */
+ /*
+  * Previously we put root temporary files in the default CUPS temporary
+  * directory under /var/spool/cups.  However, since the scheduler cleans
+  * out temporary files there and runs independently of the user apps, we
+  * don't want to use it unless specifically told to by cupsd.
+  */
 
-    if (getuid() == 0)
-      tmpdir = CUPS_REQUESTS "/tmp";
-    else
-      tmpdir = "/tmp";
-  }
+  if ((tmpdir = getenv("TMPDIR")) == NULL)
+#  ifdef __APPLE__
+    tmpdir = "/private/tmp";           /* /tmp is a symlink to /private/tmp */
+#  else
+    tmpdir = "/tmp";
+#  endif /* __APPLE__ */
 #endif /* WIN32 */
 
  /*
@@ -124,8 +116,8 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
     * Format a string using the hex time values...
     */
 
-    snprintf(filename, len - 1, "%s/%08lx%05lx", tmpdir,
-             (unsigned long)curtime.tv_sec, (unsigned long)curtime.tv_usec);
+    snprintf(filename, len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(),
+             (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
 #endif /* WIN32 */
 
    /*
@@ -158,16 +150,16 @@ cupsTempFd(char *filename,                /* I - Pointer to buffer */
 
 
 /*
- * 'cupsTempFile()' - Generate a temporary filename.
+ * 'cupsTempFile()' - Generates a temporary filename.
  *
- * The temporary filename is stored in the filename buffer.
- * This function is deprecated - use cupsTempFd() or cupsTempFile2()
- * instead.
+ * The temporary filename is returned in the filename buffer.
+ * This function is deprecated - use @link cupsTempFd@ or
+ * @link cupsTempFile2@ instead.
  *
  * @deprecated@
  */
 
-char *                                 /* O - Filename */
+char *                                 /* O - Filename or @code NULL@ on error */
 cupsTempFile(char *filename,           /* I - Pointer to buffer */
              int  len)                 /* I - Size of buffer */
 {
@@ -207,14 +199,15 @@ cupsTempFile(char *filename,              /* I - Pointer to buffer */
 
 
 /*
- * 'cupsTempFile2()' - Create a temporary CUPS file.
+ * 'cupsTempFile2()' - Creates a temporary CUPS file.
  *
- * The temporary filename is stored in the filename buffer.
+ * The temporary filename is returned in the filename buffer.
+ * The temporary file is opened for writing.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/OS X 10.5@
  */
 
-cups_file_t *                          /* O - CUPS file or NULL on error */
+cups_file_t *                          /* O - CUPS file or @code NULL@ on error */
 cupsTempFile2(char *filename,          /* I - Pointer to buffer */
               int  len)                        /* I - Size of buffer */
 {
@@ -236,5 +229,5 @@ cupsTempFile2(char *filename,               /* I - Pointer to buffer */
 
 
 /*
- * End of "$Id: tempfile.c 4918 2006-01-12 05:14:40Z mike $".
+ * End of "$Id$".
  */