19
19
#include "mysys_priv.h"
20
20
#include <mystrings/m_string.h>
21
#include <my_dir.h> /* Structs used by my_dir,includes sys/types */
22
21
#include "mysys_err.h"
22
#include "my_dir.h" /* Structs used by my_dir,includes sys/types */
23
23
#if defined(HAVE_DIRENT_H)
24
24
# include <dirent.h>
25
# define NAMLEN(dirent) strlen((dirent)->d_name)
27
26
# define dirent direct
28
# define NAMLEN(dirent) (dirent)->d_namlen
29
27
# if defined(HAVE_SYS_NDIR_H)
30
28
# include <sys/ndir.h>
65
delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer +
63
delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer +
66
64
ALIGN_SIZE(sizeof(MY_DIR))));
67
free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
65
free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
68
66
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
69
my_free((uchar*) buffer,MYF(0));
67
free((unsigned char*) buffer);
99
97
dirp = opendir(directory_file_name(tmp_path,(char *) path));
101
! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
102
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
103
sizeof(MEM_ROOT), MyFlags)))
99
! (buffer= (char *) malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
100
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
106
dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
104
dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
107
105
names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
108
106
ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
110
108
if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
111
109
ENTRIES_START_SIZE, ENTRIES_INCREMENT))
113
my_free((uchar*) buffer,MYF(0));
111
free((unsigned char*) buffer);
116
114
init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
118
116
/* MY_DIR structure is allocated and completly initialized at this point */
119
117
result= (MY_DIR*)buffer;
121
tmp_file=strend(tmp_path);
119
tmp_file= strchr(tmp_path, '\0');
123
121
dp= (struct dirent*) dirent_tmp;
125
123
while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
127
125
if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
130
128
if (MyFlags & MY_WANT_STAT)
132
if (!(finfo.mystat= (struct stat*)alloc_root(names_storage,
130
if (!(finfo.mystat= (struct stat*)alloc_root(names_storage,
133
131
sizeof(struct stat))))
136
134
memset(finfo.mystat, 0, sizeof(struct stat));
137
VOID(stpcpy(tmp_file,dp->d_name));
138
VOID(stat(tmp_path, finfo.mystat));
135
strcpy(tmp_file,dp->d_name);
136
stat(tmp_path, finfo.mystat);
139
137
if (!(finfo.mystat->st_mode & S_IREAD))
143
141
finfo.mystat= NULL;
145
if (push_dynamic(dir_entries_storage, (uchar*)&finfo))
143
if (push_dynamic(dir_entries_storage, (unsigned char*)&finfo))
153
151
result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
154
152
result->number_off_files= dir_entries_storage->elements;
156
154
if (!(MyFlags & MY_DONT_SORT))
157
155
my_qsort((void *) result->dir_entry, result->number_off_files,
158
156
sizeof(FILEINFO), (qsort_cmp) comp_names);