]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dir.c
Migrate Windows conditional code to _WIN32 define.
[thirdparty/cups.git] / cups / dir.c
index 1b6bc4369fb70e349c76ea6710f3ad95f59ed71d..89e354ad16c5a39c14d34ffa64ea46289dd6d610 100644 (file)
@@ -1,57 +1,28 @@
 /*
- * "$Id$"
+ * Directory routines for CUPS.
  *
- *   Public directory routines for the Common UNIX Printing System (CUPS).
+ * This set of APIs abstracts enumeration of directory entries.
  *
- *   This set of APIs abstracts enumeration of directory entries.
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2005 by Easy Software Products, all rights reserved.
  *
- *   Copyright 1997-2005 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
- *   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
- *
- * Contents:
- *
- *   _cups_dir_time() - Convert a FILETIME value to a UNIX time value.
- *   cupsDirClose()   - Close a directory.
- *   cupsDirOpen()    - Open a directory.
- *   cupsDirRead()    - Read the next directory entry.
- *   cupsDirRewind()  - Rewind to the start of the directory.
- *   cupsDirClose()   - Close a directory.
- *   cupsDirOpen()    - Open a directory.
- *   cupsDirRead()    - Read the next directory entry.
- *   cupsDirRewind()  - Rewind to the start of the directory.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
+#include "string-private.h"
+#include "debug-private.h"
 #include "dir.h"
-#include "string.h"
-#include "debug.h"
-#include <stdlib.h>
-#include <errno.h>
 
 
 /*
  * Windows implementation...
  */
 
-#ifdef WIN32
+#ifdef _WIN32
 #  include <windows.h>
 
 /*
@@ -82,17 +53,19 @@ _cups_dir_time(FILETIME ft)         /* I - File time */
   * between them...
   */
 
-  val = ft.dwLowDateTime + (ft.dwHighDateTime << 32);
+  val = ft.dwLowDateTime + ((ULONGLONG)ft.dwHighDateTime << 32);
   return ((time_t)(val / 10000000 - 11644732800));
 }
 
 
 /*
  * 'cupsDirClose()' - Close a directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 void
-cupsDirClose(cups_dir_t *dp)           /* I - Directory */
+cupsDirClose(cups_dir_t *dp)           /* I - Directory pointer */
 {
  /*
   * Range check input...
@@ -118,9 +91,11 @@ cupsDirClose(cups_dir_t *dp)                /* I - Directory */
 
 /*
  * 'cupsDirOpen()' - Open a directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
-cups_dir_t *                           /* O - Directory */
+cups_dir_t *                           /* O - Directory pointer or @code NULL@ if the directory could not be opened. */
 cupsDirOpen(const char *directory)     /* I - Directory name */
 {
   cups_dir_t   *dp;                    /* Directory */
@@ -159,10 +134,12 @@ cupsDirOpen(const char *directory)        /* I - Directory name */
 
 /*
  * 'cupsDirRead()' - Read the next directory entry.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
-cups_dentry_t *                        /* O - Directory entry */
-cupsDirRead(cups_dir_t *dp)            /* I - Directory */
+cups_dentry_t *                                /* O - Directory entry or @code NULL@ if there are no more */
+cupsDirRead(cups_dir_t *dp)            /* I - Directory pointer */
 {
   WIN32_FIND_DATA      entry;          /* Directory entry data */
 
@@ -205,7 +182,7 @@ cupsDirRead(cups_dir_t *dp)         /* I - Directory */
   dp->entry.fileinfo.st_atime = _cups_dir_time(entry.ftLastAccessTime);
   dp->entry.fileinfo.st_ctime = _cups_dir_time(entry.ftCreationTime);
   dp->entry.fileinfo.st_mtime = _cups_dir_time(entry.ftLastWriteTime);
-  dp->entry.fileinfo.st_size  = entry.nFileSizeLow + (entry.nFileSizeHigh << 32);
+  dp->entry.fileinfo.st_size  = entry.nFileSizeLow + ((unsigned long long)entry.nFileSizeHigh << 32);
 
  /*
   * Return the entry...
@@ -217,10 +194,12 @@ cupsDirRead(cups_dir_t *dp)               /* I - Directory */
 
 /*
  * 'cupsDirRewind()' - Rewind to the start of the directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 void
-cupsDirRewind(cups_dir_t *dp)          /* I - Directory */
+cupsDirRewind(cups_dir_t *dp)          /* I - Directory pointer */
 {
  /*
   * Range check input...
@@ -265,12 +244,14 @@ struct _cups_dir_s                        /**** Directory data structure ****/
 
 /*
  * 'cupsDirClose()' - Close a directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 void
-cupsDirClose(cups_dir_t *dp)           /* I - Directory */
+cupsDirClose(cups_dir_t *dp)           /* I - Directory pointer */
 {
-  DEBUG_printf(("cupsDirClose(dp=%p)\n", dp));
+  DEBUG_printf(("cupsDirClose(dp=%p)", (void *)dp));
 
  /*
   * Range check input...
@@ -290,15 +271,17 @@ cupsDirClose(cups_dir_t *dp)              /* I - Directory */
 
 /*
  * 'cupsDirOpen()' - Open a directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
-cups_dir_t *                           /* O - Directory */
+cups_dir_t *                           /* O - Directory pointer or @code NULL@ if the directory could not be opened. */
 cupsDirOpen(const char *directory)     /* I - Directory name */
 {
   cups_dir_t   *dp;                    /* Directory */
 
 
-  DEBUG_printf(("cupsDirOpen(directory=\"%s\")\n", directory));
+  DEBUG_printf(("cupsDirOpen(directory=\"%s\")", directory));
 
  /*
   * Range check input...
@@ -342,18 +325,18 @@ cupsDirOpen(const char *directory)        /* I - Directory name */
 
 /*
  * 'cupsDirRead()' - Read the next directory entry.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
-cups_dentry_t *                                /* O - Directory entry */
-cupsDirRead(cups_dir_t *dp)            /* I - Directory */
+cups_dentry_t *                                /* O - Directory entry or @code NULL@ when there are no more */
+cupsDirRead(cups_dir_t *dp)            /* I - Directory pointer */
 {
-  char         buffer[sizeof(struct dirent) + 1024];
-                                       /* Directory entry buffer */
   struct dirent        *entry;                 /* Pointer to entry */
   char         filename[1024];         /* Full filename */
 
 
-  DEBUG_printf(("cupsDirRead(dp=%p)\n", dp));
+  DEBUG_printf(("2cupsDirRead(dp=%p)", (void *)dp));
 
  /*
   * Range check input...
@@ -368,19 +351,21 @@ cupsDirRead(cups_dir_t *dp)               /* I - Directory */
 
   for (;;)
   {
-    if (readdir_r(dp->dir, (struct dirent *)buffer, &entry))
-    {
-      DEBUG_printf(("    readdir_r() failed - %s\n", strerror(errno)));
-      return (NULL);
-    }
+   /*
+    * Read the next entry...
+    */
 
-    if (!entry)
+    if ((entry = readdir(dp->dir)) == NULL)
     {
-      DEBUG_puts("    readdir_r() returned a NULL pointer!");
+      DEBUG_puts("3cupsDirRead: readdir() returned a NULL pointer!");
       return (NULL);
     }
 
-    DEBUG_printf(("    readdir_r() returned \"%s\"...\n", entry->d_name));
+    DEBUG_printf(("4cupsDirRead: readdir() returned \"%s\"...", entry->d_name));
+
+   /*
+    * Skip "." and ".."...
+    */
 
     if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
       continue;
@@ -395,7 +380,7 @@ cupsDirRead(cups_dir_t *dp)         /* I - Directory */
 
     if (stat(filename, &(dp->entry.fileinfo)))
     {
-      DEBUG_printf(("    stat() failed for \"%s\" - %s...\n", filename,
+      DEBUG_printf(("3cupsDirRead: stat() failed for \"%s\" - %s...", filename,
                     strerror(errno)));
       continue;
     }
@@ -411,12 +396,14 @@ cupsDirRead(cups_dir_t *dp)               /* I - Directory */
 
 /*
  * 'cupsDirRewind()' - Rewind to the start of the directory.
+ *
+ * @since CUPS 1.2/macOS 10.5@
  */
 
 void
-cupsDirRewind(cups_dir_t *dp)          /* I - Directory */
+cupsDirRewind(cups_dir_t *dp)          /* I - Directory pointer */
 {
-  DEBUG_printf(("cupsDirRewind(dp=%p)\n", dp));
+  DEBUG_printf(("cupsDirRewind(dp=%p)", (void *)dp));
 
  /*
   * Range check input...
@@ -431,10 +418,4 @@ cupsDirRewind(cups_dir_t *dp)              /* I - Directory */
 
   rewinddir(dp->dir);
 }
-
-
-#endif /* WIN32 */
-
-/*
- * End of "$Id$".
- */
+#endif /* _WIN32 */