Added errno.h
[idzebra-moved-to-github.git] / index / dir.c
index 6d0e11d..66d0316 100644 (file)
@@ -1,10 +1,26 @@
 /*
- * Copyright (C) 1995, Index Data I/S 
+ * Copyright (C) 1994-1995, Index Data I/S 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: dir.c,v $
- * Revision 1.4  1995-09-04 12:33:41  adam
+ * Revision 1.9  1995-10-30 13:42:12  adam
+ * Added errno.h
+ *
+ * Revision 1.8  1995/10/10  13:59:23  adam
+ * Function rset_open changed its wflag parameter to general flags.
+ *
+ * Revision 1.7  1995/09/28  09:19:40  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.6  1995/09/08  14:52:26  adam
+ * Minor changes. Dictionary is lower case now.
+ *
+ * Revision 1.5  1995/09/06  16:11:16  adam
+ * Option: only one word key per file.
+ *
+ * Revision 1.4  1995/09/04  12:33:41  adam
  * Various cleanup. YAZ util used instead.
  *
  * Revision 1.3  1995/09/01  14:06:35  adam
@@ -23,6 +39,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <ctype.h>
 
@@ -33,11 +50,11 @@ struct dir_entry *dir_open (const char *rep)
 {
     DIR *dir;
     struct dirent *dent;
-    size_t entry_max = 20;
+    size_t entry_max = 500;
     size_t idx = 0;
     struct dir_entry *entry;
 
-    logf (LOG_DEBUG, "dir_open %s", rep);
+    logf (LOG_LOG, "dir_open %s", rep);
     if (!(dir = opendir(rep)))
     {
         logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
@@ -45,11 +62,7 @@ struct dir_entry *dir_open (const char *rep)
             exit (1);
         return NULL;
     }
-    if (!(entry = malloc (sizeof(*entry) * entry_max)))
-    {
-        logf (LOG_FATAL|LOG_ERRNO, "malloc");
-        exit (1);
-    }    
+    entry = xmalloc (sizeof(*entry) * entry_max);
     while ((dent = readdir (dir)))
     {
         if (strcmp (dent->d_name, ".") == 0 ||
@@ -59,21 +72,13 @@ struct dir_entry *dir_open (const char *rep)
         {
             struct dir_entry *entry_n;
 
-            if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 100))))
-            {
-                logf (LOG_FATAL|LOG_ERRNO, "malloc");
-                exit (1);
-            }
+            entry_n = xmalloc (sizeof(*entry) * (entry_max + 1000));
             memcpy (entry_n, entry, idx * sizeof(*entry));
-            free (entry);
+            xfree (entry);
             entry = entry_n;
             entry_max += 100;
         }
-        if (!(entry[idx].name = malloc (strlen(dent->d_name)+1)))
-        {
-            logf (LOG_FATAL|LOG_ERRNO, "malloc");
-            exit (1);
-        }
+        entry[idx].name = xmalloc (strlen(dent->d_name)+1);
         strcpy (entry[idx].name, dent->d_name);
         idx++;
     }
@@ -103,7 +108,7 @@ void dir_free (struct dir_entry **e_p)
 
     assert (e);
     while (e[i].name)
-        free (e[i++].name);
-    free (e);
+        xfree (e[i++].name);
+    xfree (e);
     *e_p = NULL;
 }