2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-09-01 10:57:07 adam
10 * Revision 1.1 1995/09/01 10:34:51 adam
19 #include <sys/types.h>
26 struct dir_entry *dir_open (const char *rep)
30 size_t entry_max = 20;
32 struct dir_entry *entry;
34 log (LOG_DEBUG, "dir_open %s", rep);
35 if (!(dir = opendir(rep)))
37 log (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
42 if (!(entry = malloc (sizeof(*entry) * entry_max)))
44 log (LOG_FATAL|LOG_ERRNO, "malloc");
47 while ((dent = readdir (dir)))
49 if (idx == entry_max-1)
51 struct dir_entry *entry_n;
53 if (!(entry_n = malloc (sizeof(*entry) * (entry_max + 100))))
55 log (LOG_FATAL|LOG_ERRNO, "malloc");
58 memcpy (entry_n, entry, entry_max * sizeof(*entry));
63 if (!(entry[idx].name = malloc (strlen(dent->d_name)+1)))
65 log (LOG_FATAL|LOG_ERRNO, "malloc");
68 strcpy (entry[idx].name, dent->d_name);
71 entry[idx].name = NULL;
76 static int dir_cmp (const void *p1, const void *p2)
78 return strcmp (((struct dir_entry *) p1)->name,
79 ((struct dir_entry *) p2)->name);
82 void dir_sort (struct dir_entry *e)
87 qsort (e, nmemb, sizeof(*e), dir_cmp);
90 void dir_free (struct dir_entry **e_p)
93 struct dir_entry *e = *e_p;