]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/tempfile.c
Migrate Windows conditional code to _WIN32 define.
[thirdparty/cups.git] / cups / tempfile.c
index dcd81736de3e28a1b4b9dca785e629d08972a1bf..e305c6cd9d8929ca695f274b60d4ca3e20524846 100644 (file)
 #include <stdlib.h>
 #include <fcntl.h>
 #include <sys/stat.h>
-#if defined(WIN32) || defined(__EMX__)
+#if defined(_WIN32) || defined(__EMX__)
 #  include <io.h>
 #else
 #  include <unistd.h>
-#endif /* WIN32 || __EMX__ */
+#endif /* _WIN32 || __EMX__ */
 
 
 /*
@@ -37,21 +37,21 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
   int          fd;                     /* File descriptor for temp file */
   int          tries;                  /* Number of tries */
   const char   *tmpdir;                /* TMPDIR environment var */
-#if defined(__APPLE__) || defined(WIN32)
+#if defined(__APPLE__) || defined(_WIN32)
   char         tmppath[1024];          /* Temporary directory */
-#endif /* __APPLE__ || WIN32 */
-#ifdef WIN32
+#endif /* __APPLE__ || _WIN32 */
+#ifdef _WIN32
   DWORD                curtime;                /* Current time */
 #else
   struct timeval curtime;              /* Current time */
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 
  /*
   * See if TMPDIR is defined...
   */
 
-#ifdef WIN32
+#ifdef _WIN32
   if ((tmpdir = getenv("TEMP")) == NULL)
   {
     GetTempPath(sizeof(tmppath), tmppath);
@@ -63,11 +63,10 @@ cupsTempFd(char *filename,          /* I - Pointer to buffer */
   * On macOS and iOS, the TMPDIR environment variable is not always the best
   * location to place temporary files due to sandboxing.  Instead, the confstr
   * function should be called to get the proper per-user, per-process TMPDIR
-  * value.  Currently this only happens if TMPDIR is not set or is set to
-  * "/var/folders/...".
+  * value.
   */
 
-  if ((tmpdir = getenv("TMPDIR")) != NULL && !strncmp(tmpdir, "/var/folders/", 13))
+  if ((tmpdir = getenv("TMPDIR")) != NULL && access(tmpdir, W_OK))
     tmpdir = NULL;
 
   if (!tmpdir)
@@ -88,7 +87,7 @@ cupsTempFd(char *filename,            /* I - Pointer to buffer */
 
   if ((tmpdir = getenv("TMPDIR")) == NULL)
     tmpdir = "/tmp";
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
  /*
   * Make the temporary name using the specified directory...
@@ -98,7 +97,7 @@ cupsTempFd(char *filename,            /* I - Pointer to buffer */
 
   do
   {
-#ifdef WIN32
+#ifdef _WIN32
    /*
     * Get the current time of day...
     */
@@ -122,21 +121,21 @@ cupsTempFd(char *filename,                /* I - Pointer to buffer */
     */
 
     snprintf(filename, (size_t)len - 1, "%s/%05x%08x", tmpdir, (unsigned)getpid(), (unsigned)(curtime.tv_sec + curtime.tv_usec + tries));
-#endif /* WIN32 */
+#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 WIN32
+#ifdef _WIN32
     fd = open(filename, _O_CREAT | _O_RDWR | _O_TRUNC | _O_BINARY,
               _S_IREAD | _S_IWRITE);
 #elif defined(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 /* WIN32 */
+#endif /* _WIN32 */
 
     if (fd < 0 && errno != EEXIST)
       break;