MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_dir

Function my_dir

mysys/my_lib.c:91–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89#if !defined(_WIN32)
90
91MY_DIR *my_dir(const char *path, myf MyFlags)
92{
93 char *buffer;
94 MY_DIR *result= 0;
95 FILEINFO finfo;
96 DYNAMIC_ARRAY *dir_entries_storage;
97 MEM_ROOT *names_storage;
98 DIR *dirp;
99 struct dirent *dp;
100 char tmp_path[FN_REFLEN + 2], *tmp_file;
101 char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
102
103 DBUG_ENTER("my_dir");
104 DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
105
106#if !defined(HAVE_READDIR_R)
107 mysql_mutex_lock(&THR_LOCK_open);
108#endif
109
110 dirp = opendir(directory_file_name(tmp_path,(char *) path));
111#if defined(__amiga__)
112 if ((dirp->dd_fd) < 0) /* Directory doesn't exists */
113 goto error;
114#endif
115 if (dirp == NULL ||
116 ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
117 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
118 sizeof(MEM_ROOT), MyFlags)))
119 goto error;
120
121 dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
122 names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
123 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
124
125 if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
126 ENTRIES_START_SIZE, ENTRIES_INCREMENT))
127 {
128 my_free(buffer);
129 goto error;
130 }
131 init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
132
133 /* MY_DIR structure is allocated and completly initialized at this point */
134 result= (MY_DIR*)buffer;
135
136 tmp_file=strend(tmp_path);
137
138 dp= (struct dirent*) dirent_tmp;
139
140 while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
141 {
142 if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
143 goto error;
144
145 if (MyFlags & MY_WANT_STAT)
146 {
147 if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
148 sizeof(MY_STAT))))

Callers 5

find_uniq_filenameFunction · 0.85
rename_in_schema_fileFunction · 0.85
mainFunction · 0.85

Calls 13

directory_file_nameFunction · 0.85
my_mallocFunction · 0.85
my_freeFunction · 0.85
init_alloc_rootFunction · 0.85
strendFunction · 0.85
strdup_rootFunction · 0.85
alloc_rootFunction · 0.85
strmovFunction · 0.85
my_qsortFunction · 0.85
my_direndFunction · 0.85
my_errorFunction · 0.85
my_strerrorFunction · 0.85

Tested by 1

mainFunction · 0.68