]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/tempfile.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / tempfile.c
index 1503b4f7da9d1a7bbd23fddfdeb9d4bef46c4b29..cd887f901e830bec194ce5281e917efc1998a495 100644 (file)
@@ -1,34 +1,18 @@
 /*
- * "$Id: tempfile.c 7337 2008-02-22 04:44:04Z mike $"
+ * Temp file utilities for CUPS.
  *
- *   Temp file utilities for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2008 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   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()    - Creates a temporary file.
- *   cupsTempFile()  - Generates a temporary filename.
- *   cupsTempFile2() - Creates a temporary CUPS file.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * 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__)
@@ -79,11 +63,11 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
   */
 
   if ((tmpdir = getenv("TMPDIR")) == NULL)
-#  ifdef __APPLE__
+#  if defined(__APPLE__) && !TARGET_OS_IOS
     tmpdir = "/private/tmp";           /* /tmp is a symlink to /private/tmp */
 #  else
     tmpdir = "/tmp";
-#  endif /* __APPLE__ */
+#  endif /* __APPLE__  && !TARGET_OS_IOS */
 #endif /* WIN32 */
 
  /*
@@ -105,8 +89,7 @@ cupsTempFd(char *filename,           /* I - Pointer to buffer */
     * Format a string using the hex time values...
     */
 
-    snprintf(filename, len - 1, "%s/%05lx%08lx", tmpdir,
-             GetCurrentProcessId(), curtime);
+    snprintf(filename, (size_t)len - 1, "%s/%05lx%08lx", tmpdir, GetCurrentProcessId(), curtime);
 #else
    /*
     * Get the current time of day...
@@ -118,8 +101,7 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
     * Format a string using the hex time values...
     */
 
-    snprintf(filename, len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(),
-             (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
+    snprintf(filename, (size_t)len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(), (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
 #endif /* WIN32 */
 
    /*
@@ -155,8 +137,8 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
  * 'cupsTempFile()' - Generates a temporary filename.
  *
  * The temporary filename is returned in the filename buffer.
- * This function is deprecated - use @link cupsTempFd@ or
- * @link cupsTempFile2@ instead.
+ * This function is deprecated and will no longer generate a temporary
+ * filename - use @link cupsTempFd@ or @link cupsTempFile2@ instead.
  *
  * @deprecated@
  */
@@ -165,38 +147,12 @@ char *                                    /* O - Filename or @code NULL@ on error */
 cupsTempFile(char *filename,           /* I - Pointer to buffer */
              int  len)                 /* I - Size of buffer */
 {
-  int          fd;                     /* File descriptor for temp file */
-  _cups_globals_t *cg = _cupsGlobals();        /* Pointer to library globals */
-
-
- /*
-  * See if a filename was specified...
-  */
-
-  if (filename == NULL)
-  {
-    filename = cg->tempfile;
-    len      = sizeof(cg->tempfile);
-  }
-
- /*
-  * Create the temporary file...
-  */
-
-  if ((fd = cupsTempFd(filename, len)) < 0)
-    return (NULL);
-
- /*
-  * Close the temp file - it'll be reopened later as needed...
-  */
+  (void)len;
 
-  close(fd);
+  if (filename)
+    *filename = '\0';
 
- /*
-  * Return the temp filename...
-  */
-
-  return (filename);
+  return (NULL);
 }
 
 
@@ -206,7 +162,7 @@ cupsTempFile(char *filename,                /* I - Pointer to buffer */
  * The temporary filename is returned in the filename buffer.
  * The temporary file is opened for writing.
  *
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 cups_file_t *                          /* O - CUPS file or @code NULL@ on error */
@@ -228,8 +184,3 @@ cupsTempFile2(char *filename,               /* I - Pointer to buffer */
   else
     return (file);
 }
-
-
-/*
- * End of "$Id: tempfile.c 7337 2008-02-22 04:44:04Z mike $".
- */