]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dir.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / dir.c
index e06edea91ccc34c20a6874c579b446fab0960ada..b3a689b70d11416d5022c8ffa37b13d6d12561fd 100644 (file)
@@ -5,23 +5,14 @@
  *
  *   This set of APIs abstracts enumeration of directory entries.
  *
+ *   Copyright 2007 by Apple Inc.
  *   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
+ *   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/".
  *
  * Contents:
  *
@@ -347,10 +338,12 @@ cupsDirOpen(const char *directory)        /* I - Directory name */
 cups_dentry_t *                                /* O - Directory entry */
 cupsDirRead(cups_dir_t *dp)            /* I - Directory */
 {
-  char         buffer[sizeof(struct dirent) + 1024];
-                                       /* Directory entry buffer */
   struct dirent        *entry;                 /* Pointer to entry */
   char         filename[1024];         /* Full filename */
+#  ifdef HAVE_PTHREAD_H
+  char         buffer[sizeof(struct dirent) + 1024];
+                                       /* Directory entry buffer */
+#  endif /* HAVE_PTHREAD_H */
 
 
   DEBUG_printf(("cupsDirRead(dp=%p)\n", dp));
@@ -366,8 +359,13 @@ cupsDirRead(cups_dir_t *dp)                /* I - Directory */
   * Try reading an entry that is not "." or ".."...
   */
 
-  do
+  for (;;)
   {
+#  ifdef HAVE_PTHREAD_H
+   /*
+    * Read the next entry using the reentrant version of readdir...
+    */
+
     if (readdir_r(dp->dir, (struct dirent *)buffer, &entry))
     {
       DEBUG_printf(("    readdir_r() failed - %s\n", strerror(errno)));
@@ -381,28 +379,50 @@ cupsDirRead(cups_dir_t *dp)               /* I - Directory */
     }
 
     DEBUG_printf(("    readdir_r() returned \"%s\"...\n", entry->d_name));
-  }
-  while (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."));
 
- /*
-  * Copy the name over and get the file information...
-  */
+#  else
+   /*
+    * Read the next entry using the original version of readdir...
+    */
 
-  strlcpy(dp->entry.filename, entry->d_name, sizeof(dp->entry.filename));
+    if ((entry = readdir(dp->dir)) == NULL)
+    {
+      DEBUG_puts("    readdir() returned a NULL pointer!");
+      return (NULL);
+    }
 
-  snprintf(filename, sizeof(filename), "%s/%s", dp->directory, entry->d_name);
-  if (stat(filename, &(dp->entry.fileinfo)))
-  {
-    DEBUG_printf(("    stat() failed for \"%s\" - %s...\n", filename,
-                  strerror(errno)));
-    return (NULL);
-  }
+    DEBUG_printf(("    readdir() returned \"%s\"...\n", entry->d_name));
 
- /*
-  * Return the entry...
-  */
+#  endif /* HAVE_PTHREAD_H */
 
-  return (&(dp->entry));
+   /*
+    * Skip "." and ".."...
+    */
+
+    if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
+      continue;
+
+   /*
+    * Copy the name over and get the file information...
+    */
+
+    strlcpy(dp->entry.filename, entry->d_name, sizeof(dp->entry.filename));
+
+    snprintf(filename, sizeof(filename), "%s/%s", dp->directory, entry->d_name);
+
+    if (stat(filename, &(dp->entry.fileinfo)))
+    {
+      DEBUG_printf(("    stat() failed for \"%s\" - %s...\n", filename,
+                    strerror(errno)));
+      continue;
+    }
+
+   /*
+    * Return the entry...
+    */
+
+    return (&(dp->entry));
+  }
 }