]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/dir.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / dir.c
index e06edea91ccc34c20a6874c579b446fab0960ada..c130bd8653d1002ab05c49be8406a2212c4f31b1 100644 (file)
@@ -347,10 +347,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 +368,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 +388,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));
+  }
 }