2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.14 1996-04-09 06:49:18 adam
8 * Traversal of directories doesn't follow symbolic links.
10 * Revision 1.13 1996/03/21 14:50:08 adam
11 * File update uses modify-time instead of change-time.
13 * Revision 1.12 1996/02/05 12:29:55 adam
14 * Logging reduced a bit.
15 * The remaining running time is estimated during register merge.
17 * Revision 1.11 1995/11/20 16:59:44 adam
18 * New update method: the 'old' keys are saved for each records.
20 * Revision 1.10 1995/11/20 11:56:22 adam
21 * Work on new traversal.
23 * Revision 1.9 1995/10/30 13:42:12 adam
26 * Revision 1.8 1995/10/10 13:59:23 adam
27 * Function rset_open changed its wflag parameter to general flags.
29 * Revision 1.7 1995/09/28 09:19:40 adam
30 * xfree/xmalloc used everywhere.
31 * Extract/retrieve method seems to work for text records.
33 * Revision 1.6 1995/09/08 14:52:26 adam
34 * Minor changes. Dictionary is lower case now.
36 * Revision 1.5 1995/09/06 16:11:16 adam
37 * Option: only one word key per file.
39 * Revision 1.4 1995/09/04 12:33:41 adam
40 * Various cleanup. YAZ util used instead.
42 * Revision 1.3 1995/09/01 14:06:35 adam
43 * Split of work into more files.
45 * Revision 1.2 1995/09/01 10:57:07 adam
48 * Revision 1.1 1995/09/01 10:34:51 adam
58 #include <sys/types.h>
66 struct dir_entry *dir_open (const char *rep)
72 size_t entry_max = 500;
74 struct dir_entry *entry;
76 logf (LOG_DEBUG, "dir_open %s", rep);
77 if (!(dir = opendir(rep)))
79 logf (LOG_WARN|LOG_ERRNO, "opendir %s", rep);
80 if (errno != ENOENT && errno != EACCES)
84 entry = xmalloc (sizeof(*entry) * entry_max);
86 pathpos = strlen(path);
87 if (!pathpos || path[pathpos-1] != '/')
88 path[pathpos++] = '/';
89 while ((dent = readdir (dir)))
92 if (strcmp (dent->d_name, ".") == 0 ||
93 strcmp (dent->d_name, "..") == 0)
95 if (idx == entry_max-1)
97 struct dir_entry *entry_n;
99 entry_n = xmalloc (sizeof(*entry) * (entry_max += 1000));
100 memcpy (entry_n, entry, idx * sizeof(*entry));
104 strcpy (path + pathpos, dent->d_name);
105 lstat (path, &finfo);
106 switch (finfo.st_mode & S_IFMT)
109 entry[idx].kind = dirs_file;
110 entry[idx].mtime = finfo.st_mtime;
111 entry[idx].name = xmalloc (strlen(dent->d_name)+1);
112 strcpy (entry[idx].name, dent->d_name);
116 entry[idx].kind = dirs_dir;
117 entry[idx].mtime = finfo.st_mtime;
118 entry[idx].name = xmalloc (strlen(dent->d_name)+2);
119 strcpy (entry[idx].name, dent->d_name);
120 strcat (entry[idx].name, "/");
125 entry[idx].name = NULL;
127 logf (LOG_DEBUG, "dir_close");
131 static int dir_cmp (const void *p1, const void *p2)
133 return strcmp (((struct dir_entry *) p1)->name,
134 ((struct dir_entry *) p2)->name);
137 void dir_sort (struct dir_entry *e)
140 while (e[nmemb].name)
142 qsort (e, nmemb, sizeof(*e), dir_cmp);
145 void dir_free (struct dir_entry **e_p)
148 struct dir_entry *e = *e_p;