#include "mysys_priv.h"#include <m_string.h>#include <my_dir.h>#include "mysys_err.h"Include dependency graph for my_lib.c:

Go to the source code of this file.
Defines | |
| #define | dirent direct |
| #define | NAMLEN(dirent) (dirent)->d_namlen |
| #define | READDIR(A, B, C) (!(C=readdir(A))) |
| #define | ENTRIES_START_SIZE (8192/sizeof(FILEINFO)) |
| #define | ENTRIES_INCREMENT (65536/sizeof(FILEINFO)) |
| #define | NAMES_START_SIZE 32768 |
Functions | |
| static int | comp_names (struct fileinfo *a, struct fileinfo *b) |
| void | my_dirend (MY_DIR *buffer) |
| MY_DIR * | my_dir (const char *path, myf MyFlags) |
| my_string | directory_file_name (my_string dst, const char *src) |
| int | my_fstat (int Filedes, MY_STAT *stat_area, myf MyFlags __attribute__((unused))) |
| MY_STAT * | my_stat (const char *path, MY_STAT *stat_area, myf my_flags) |
Definition at line 212 of file my_lib.c.
References directory_file_name(), FN_DEVCHAR, FN_LIBCHAR, getenv(), strchr(), strcmp(), strlen(), strmake(), strmov(), strrchr(), and VOID.
Referenced by directory_file_name(), and my_dir().
00213 { 00214 #ifndef VMS 00215 00216 /* Process as Unix format: just remove test the final slash. */ 00217 00218 my_string end; 00219 00220 if (src[0] == 0) 00221 src= (char*) "."; /* Use empty as current */ 00222 end=strmov(dst, src); 00223 if (end[-1] != FN_LIBCHAR) 00224 { 00225 end[0]=FN_LIBCHAR; /* Add last '/' */ 00226 end[1]='\0'; 00227 } 00228 return dst; 00229 00230 #else /* VMS */ 00231 00232 long slen; 00233 long rlen; 00234 my_string ptr, rptr; 00235 char bracket; 00236 struct FAB fab = cc$rms_fab; 00237 struct NAM nam = cc$rms_nam; 00238 char esa[NAM$C_MAXRSS]; 00239 00240 if (! src[0]) 00241 src="[.]"; /* Empty is == current dir */ 00242 00243 slen = strlen (src) - 1; 00244 if (src[slen] == FN_C_AFTER_DIR || src[slen] == FN_C_AFTER_DIR_2 || 00245 src[slen] == FN_DEVCHAR) 00246 { 00247 /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */ 00248 fab.fab$l_fna = src; 00249 fab.fab$b_fns = slen + 1; 00250 fab.fab$l_nam = &nam; 00251 fab.fab$l_fop = FAB$M_NAM; 00252 00253 nam.nam$l_esa = esa; 00254 nam.nam$b_ess = sizeof esa; 00255 nam.nam$b_nop |= NAM$M_SYNCHK; 00256 00257 /* We call SYS$PARSE to handle such things as [--] for us. */ 00258 if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL) 00259 { 00260 slen = nam.nam$b_esl - 1; 00261 if (esa[slen] == ';' && esa[slen - 1] == '.') 00262 slen -= 2; 00263 esa[slen + 1] = '\0'; 00264 src = esa; 00265 } 00266 if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) 00267 { 00268 /* what about when we have logical_name:???? */ 00269 if (src[slen] == FN_DEVCHAR) 00270 { /* Xlate logical name and see what we get */ 00271 VOID(strmov(dst,src)); 00272 dst[slen] = 0; /* remove colon */ 00273 if (!(src = getenv (dst))) 00274 return dst; /* Can't translate */ 00275 00276 /* should we jump to the beginning of this procedure? 00277 Good points: allows us to use logical names that xlate 00278 to Unix names, 00279 Bad points: can be a problem if we just translated to a device 00280 name... 00281 For now, I'll punt and always expect VMS names, and hope for 00282 the best! */ 00283 00284 slen = strlen (src) - 1; 00285 if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) 00286 { /* no recursion here! */ 00287 VOID(strmov(dst, src)); 00288 return(dst); 00289 } 00290 } 00291 else 00292 { /* not a directory spec */ 00293 VOID(strmov(dst, src)); 00294 return(dst); 00295 } 00296 } 00297 00298 bracket = src[slen]; /* End char */ 00299 if (!(ptr = strchr (src, bracket - 2))) 00300 { /* no opening bracket */ 00301 VOID(strmov (dst, src)); 00302 return dst; 00303 } 00304 if (!(rptr = strrchr (src, '.'))) 00305 rptr = ptr; 00306 slen = rptr - src; 00307 VOID(strmake (dst, src, slen)); 00308 00309 if (*rptr == '.') 00310 { /* Put bracket and add */ 00311 dst[slen++] = bracket; /* (rptr+1) after this */ 00312 } 00313 else 00314 { 00315 /* If we have the top-level of a rooted directory (i.e. xx:[000000]), 00316 then translate the device and recurse. */ 00317 00318 if (dst[slen - 1] == ':' 00319 && dst[slen - 2] != ':' /* skip decnet nodes */ 00320 && strcmp(src + slen, "[000000]") == 0) 00321 { 00322 dst[slen - 1] = '\0'; 00323 if ((ptr = getenv (dst)) 00324 && (rlen = strlen (ptr) - 1) > 0 00325 && (ptr[rlen] == FN_C_AFTER_DIR || ptr[rlen] == FN_C_AFTER_DIR_2) 00326 && ptr[rlen - 1] == '.') 00327 { 00328 VOID(strmov(esa,ptr)); 00329 esa[rlen - 1] = FN_C_AFTER_DIR; 00330 esa[rlen] = '\0'; 00331 return (directory_file_name (dst, esa)); 00332 } 00333 else 00334 dst[slen - 1] = ':'; 00335 } 00336 VOID(strmov(dst+slen,"[000000]")); 00337 slen += 8; 00338 } 00339 VOID(strmov(strmov(dst+slen,rptr+1)-1,".DIR.1")); 00340 return dst; 00341 } 00342 VOID(strmov(dst, src)); 00343 if (dst[slen] == '/' && slen > 1) 00344 dst[slen] = 0; 00345 return dst; 00346 #endif /* VMS */ 00347 } /* directory_file_name */
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 98 of file my_lib.c.
References ALIGN_SIZE, alloc_root(), st_dynamic_array::buffer, buffer, bzero, comp_names(), DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, st_my_dir::dir_entry, directory_file_name(), dirent, EE_DIR, st_dynamic_array::elements, ENTRIES_INCREMENT, ENTRIES_START_SIZE, errno, error, FN_REFLEN, init_alloc_root(), ME_BELL, ME_WAITTANG, my_dirend(), MY_DONT_SORT, my_errno, my_error(), MY_FAE, my_free, my_init_dynamic_array, my_malloc(), MY_S_IREAD, my_stat(), MY_STAT, MY_WANT_STAT, MY_WME, MYF, fileinfo::mystat, fileinfo::name, NAMES_START_SIZE, NULL, st_my_dir::number_off_files, pthread_mutex_lock, pthread_mutex_unlock, push_dynamic, qsort(), qsort_cmp, READDIR, strdup_root(), strend(), strmov(), and VOID.
Referenced by find_files(), find_uniq_filename(), main(), mysql_rename_db(), mysql_rm_db(), mysql_rm_known_files(), mysql_rm_tmp_tables(), and search_default_file_with_ext().
00099 { 00100 char *buffer; 00101 MY_DIR *result= 0; 00102 FILEINFO finfo; 00103 DYNAMIC_ARRAY *dir_entries_storage; 00104 MEM_ROOT *names_storage; 00105 DIR *dirp; 00106 struct dirent *dp; 00107 char tmp_path[FN_REFLEN+1],*tmp_file; 00108 #ifdef THREAD 00109 char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; 00110 #endif 00111 DBUG_ENTER("my_dir"); 00112 DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); 00113 00114 #if defined(THREAD) && !defined(HAVE_READDIR_R) 00115 pthread_mutex_lock(&THR_LOCK_open); 00116 #endif 00117 00118 dirp = opendir(directory_file_name(tmp_path,(my_string) path)); 00119 #if defined(__amiga__) 00120 if ((dirp->dd_fd) < 0) /* Directory doesn't exists */ 00121 goto error; 00122 #endif 00123 if (dirp == NULL || 00124 ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + 00125 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + 00126 sizeof(MEM_ROOT), MyFlags))) 00127 goto error; 00128 00129 dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); 00130 names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 00131 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); 00132 00133 if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), 00134 ENTRIES_START_SIZE, ENTRIES_INCREMENT)) 00135 { 00136 my_free((gptr) buffer,MYF(0)); 00137 goto error; 00138 } 00139 init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); 00140 00141 /* MY_DIR structure is allocated and completly initialized at this point */ 00142 result= (MY_DIR*)buffer; 00143 00144 tmp_file=strend(tmp_path); 00145 00146 #ifdef THREAD 00147 dp= (struct dirent*) dirent_tmp; 00148 #else 00149 dp=0; 00150 #endif 00151 00152 while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp))) 00153 { 00154 if (!(finfo.name= strdup_root(names_storage, dp->d_name))) 00155 goto error; 00156 00157 if (MyFlags & MY_WANT_STAT) 00158 { 00159 if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, 00160 sizeof(MY_STAT)))) 00161 goto error; 00162 00163 bzero(finfo.mystat, sizeof(MY_STAT)); 00164 VOID(strmov(tmp_file,dp->d_name)); 00165 VOID(my_stat(tmp_path, finfo.mystat, MyFlags)); 00166 if (!(finfo.mystat->st_mode & MY_S_IREAD)) 00167 continue; 00168 } 00169 else 00170 finfo.mystat= NULL; 00171 00172 if (push_dynamic(dir_entries_storage, (gptr)&finfo)) 00173 goto error; 00174 } 00175 00176 (void) closedir(dirp); 00177 #if defined(THREAD) && !defined(HAVE_READDIR_R) 00178 pthread_mutex_unlock(&THR_LOCK_open); 00179 #endif 00180 result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; 00181 result->number_off_files= dir_entries_storage->elements; 00182 00183 if (!(MyFlags & MY_DONT_SORT)) 00184 qsort((void *) result->dir_entry, result->number_off_files, 00185 sizeof(FILEINFO), (qsort_cmp) comp_names); 00186 DBUG_RETURN(result); 00187 00188 error: 00189 #if defined(THREAD) && !defined(HAVE_READDIR_R) 00190 pthread_mutex_unlock(&THR_LOCK_open); 00191 #endif 00192 my_errno=errno; 00193 if (dirp) 00194 (void) closedir(dirp); 00195 my_dirend(result); 00196 if (MyFlags & (MY_FAE | MY_WME)) 00197 my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); 00198 DBUG_RETURN((MY_DIR *) NULL); 00199 } /* my_dir */
Here is the call graph for this function:

Here is the caller graph for this function:

| void my_dirend | ( | MY_DIR * | buffer | ) |
Definition at line 73 of file my_lib.c.
References ALIGN_SIZE, buffer, DBUG_ENTER, DBUG_VOID_RETURN, delete_dynamic(), free_root(), my_free, and MYF.
Referenced by find_files(), find_uniq_filename(), my_dir(), mysql_rename_db(), mysql_rm_arc_files(), mysql_rm_known_files(), and search_default_file_with_ext().
00074 { 00075 DBUG_ENTER("my_dirend"); 00076 if (buffer) 00077 { 00078 delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer + 00079 ALIGN_SIZE(sizeof(MY_DIR)))); 00080 free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) + 00081 ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0)); 00082 my_free((gptr) buffer,MYF(0)); 00083 } 00084 DBUG_VOID_RETURN; 00085 } /* my_dirend */
Here is the call graph for this function:

Here is the caller graph for this function:

| int my_fstat | ( | int | Filedes, | |
| MY_STAT * | stat_area, | |||
| myf MyFlags | __attribute__((unused)) | |||
| ) |
Definition at line 518 of file my_lib.c.
References DBUG_ENTER, DBUG_PRINT, and DBUG_RETURN.
00520 { 00521 DBUG_ENTER("my_fstat"); 00522 DBUG_PRINT("my",("fd: %d MyFlags: %d",Filedes,MyFlags)); 00523 DBUG_RETURN(fstat(Filedes, (struct stat *) stat_area)); 00524 }
| MY_STAT* my_stat | ( | const char * | path, | |
| MY_STAT * | stat_area, | |||
| myf | my_flags | |||
| ) |
Definition at line 527 of file my_lib.c.
References DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, EE_STAT, errno, error, ME_BELL, ME_WAITTANG, my_errno, my_error(), MY_FAE, my_free, my_malloc(), MY_WME, MYF, and NULL.
Referenced by com_edit(), create_sys_files(), dyn_string_cmp(), File_class::exists(), find_files(), get_options(), get_share(), ha_archive::info(), main(), my_copy(), my_dir(), my_read_charset_file(), my_rename(), mysql_create_db(), mysql_load(), prepare_for_repair(), search_default_file_with_ext(), sql_parse_prepare(), sys_check_log_path(), test_file_exists_res(), test_if_case_insensitive(), and Item_load_file::val_str().
00528 { 00529 int m_used; 00530 DBUG_ENTER("my_stat"); 00531 DBUG_PRINT("my", ("path: '%s', stat_area: 0x%lx, MyFlags: %d", path, 00532 (byte *) stat_area, my_flags)); 00533 00534 if ((m_used= (stat_area == NULL))) 00535 if (!(stat_area = (MY_STAT *) my_malloc(sizeof(MY_STAT), my_flags))) 00536 goto error; 00537 if (! stat((my_string) path, (struct stat *) stat_area) ) 00538 DBUG_RETURN(stat_area); 00539 00540 DBUG_PRINT("error",("Got errno: %d from stat", errno)); 00541 my_errno= errno; 00542 if (m_used) /* Free if new area */ 00543 my_free((gptr) stat_area,MYF(0)); 00544 00545 error: 00546 if (my_flags & (MY_FAE+MY_WME)) 00547 { 00548 my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno); 00549 DBUG_RETURN((MY_STAT *) NULL); 00550 } 00551 DBUG_RETURN((MY_STAT *) NULL); 00552 } /* my_stat */
Here is the call graph for this function:

Here is the caller graph for this function:

1.4.7

