2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-09-01 10:34:51 adam
16 #include <sys/types.h>
23 struct dir_entry *dir_open (const char *rep)
27 size_t entry_max = 20;
29 struct dir_entry *entry;
31 log (LOG_DEBUG, "dir_open %s", rep);
32 if (!(dir = opendir(rep)))
34 log (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
39 if (!(entry = malloc (sizeof(*entry) * entry_max)))
41 log (LOG_FATAL|LOG_ERRNO, "malloc");
44 while ((dent = readdir (dir)))
46 if (idx == entry_max-1)
48 struct dir_entry *entry_n;
50 if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 100))))
52 log (LOG_FATAL|LOG_ERRNO, "malloc");
55 memcpy (entry_n, entry, entry_max * sizeof(*entry));
60 if (!(entry[idx].name = malloc (strlen(dent->d_name)+1)))
62 log (LOG_FATAL|LOG_ERRNO, "malloc");
65 strcpy (entry[idx].name, dent->d_name);
67 entry[idx].name = NULL;
72 int dir_cmp (const void *p1, const void *p2)
74 return strcmp (((struct dir_entry *) p1)->name,
75 ((struct dir_entry *) p2)->name);
78 void dir_sort (struct dir_entry *e)
83 qsort (e, nmemb, sizeof(*e), dir_cmp);
86 void dir_free (struct dir_entry **e_p)
89 struct dir_entry *e = *e_p;