gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r7274 - GNUnet/src/util/disk


From: gnunet
Subject: [GNUnet-SVN] r7274 - GNUnet/src/util/disk
Date: Thu, 19 Jun 2008 08:04:20 -0600 (MDT)

Author: moon
Date: 2008-06-19 08:04:20 -0600 (Thu, 19 Jun 2008)
New Revision: 7274

Modified:
   GNUnet/src/util/disk/storage.c
Log:
sort files in alpahbetical order when returning them (nice in UIs and in 
gnunet-directories)


Modified: GNUnet/src/util/disk/storage.c
===================================================================
--- GNUnet/src/util/disk/storage.c      2008-06-18 21:51:00 UTC (rev 7273)
+++ GNUnet/src/util/disk/storage.c      2008-06-19 14:04:20 UTC (rev 7274)
@@ -523,10 +523,10 @@
                             GNUNET_DirectoryEntryCallback callback,
                             void *data)
 {
-  DIR *dinfo;
-  struct dirent *finfo;
+  struct dirent **finfo = NULL;
   struct stat istat;
-  int count = 0;
+  int count;
+  int n;
 
   GNUNET_GE_ASSERT (ectx, dirName != NULL);
   if (0 != STAT (dirName, &istat))
@@ -543,33 +543,36 @@
                      _("Expected `%s' to be a directory!\n"), dirName);
       return GNUNET_SYSERR;
     }
-  errno = 0;
-  dinfo = OPENDIR (dirName);
-  if ((errno == EACCES) || (dinfo == NULL))
+  count = scandir (dirName, &finfo, 0, alphasort);
+  if (count < 0)
     {
       GNUNET_GE_LOG_STRERROR_FILE (ectx,
                                    GNUNET_GE_WARNING | GNUNET_GE_USER |
-                                   GNUNET_GE_BULK, "opendir", dirName);
-      if (dinfo != NULL)
-        closedir (dinfo);
+                                   GNUNET_GE_BULK, "scandir", dirName);
+      if (finfo != NULL)
+        GNUNET_free (finfo);
       return GNUNET_SYSERR;
     }
-  while ((finfo = readdir (dinfo)) != NULL)
+  n = count;
+  while (n--)
     {
-      if ((0 == strcmp (finfo->d_name, ".")) ||
-          (0 == strcmp (finfo->d_name, "..")))
+      if ((0 == strcmp (finfo[n]->d_name, ".")) ||
+          (0 == strcmp (finfo[n]->d_name, "..")))
         continue;
       if (callback != NULL)
         {
-          if (GNUNET_OK != callback (finfo->d_name, dirName, data))
+          if (GNUNET_OK != callback (finfo[n]->d_name, dirName, data))
             {
-              closedir (dinfo);
+              GNUNET_free (finfo[n]);
+              while (n--)
+                GNUNET_free (finfo[n]);
+              GNUNET_free (finfo);
               return GNUNET_SYSERR;
             }
         }
-      count++;
+        GNUNET_free (finfo[n]);
     }
-  closedir (dinfo);
+  GNUNET_free (finfo);
   return count;
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]