31 #include <sys/types.h>
43 return lstat(file_name, buf);
45 return stat(file_name, buf);
55 struct dirent dent_s, *dent = &dent_s;
56 size_t entry_max = 500;
60 if (base && !yaz_is_abspath(rep))
62 strcpy(full_rep, base);
63 strcat(full_rep,
"/");
67 strcat(full_rep, rep);
69 yaz_log(YLOG_DEBUG,
"dir_open %s", full_rep);
70 if (!(dir = opendir(full_rep)))
72 yaz_log(YLOG_WARN|YLOG_ERRNO,
"opendir %s", rep);
75 entry = (
struct dir_entry *) xmalloc(
sizeof(*entry) * entry_max);
77 pathpos = strlen(path);
78 if (!pathpos || path[pathpos-1] !=
'/')
79 path[pathpos++] =
'/';
80 while ( (dent = readdir(dir)) )
83 if (strcmp(dent->d_name,
".") == 0 ||
84 strcmp(dent->d_name,
"..") == 0)
86 if (idx == entry_max-1)
91 xmalloc(
sizeof(*entry) * (entry_max += 1000));
92 memcpy(entry_n, entry, idx *
sizeof(*entry));
96 strcpy(path + pathpos, dent->d_name);
98 if (base && !yaz_is_abspath(path))
100 strcpy(full_rep, base);
101 strcat(full_rep,
"/");
102 strcat(full_rep, path);
107 switch (finfo.st_mode & S_IFMT)
111 entry[idx].
mtime = finfo.st_mtime;
112 entry[idx].
name = (
char *) xmalloc(strlen(dent->d_name)+1);
113 strcpy(entry[idx].
name, dent->d_name);
118 entry[idx].
mtime = finfo.st_mtime;
119 entry[idx].
name = (
char *) xmalloc(strlen(dent->d_name)+2);
120 strcpy(entry[idx].
name, dent->d_name);
121 strcat(entry[idx].
name,
"/");
126 entry[idx].
name = NULL;
128 yaz_log(YLOG_DEBUG,
"dir_close");
132 static int dir_cmp(
const void *p1,
const void *p2)
141 while (e[nmemb].
name)
143 qsort(e, nmemb,
sizeof(*e),
dir_cmp);
struct dir_entry * dir_open(const char *rep, const char *base, int follow_links)
void dir_sort(struct dir_entry *e)
int zebra_file_stat(const char *file_name, struct stat *buf, int follow_links)
static int dir_cmp(const void *p1, const void *p2)
void dir_free(struct dir_entry **e_p)