static void prepare_server_struct_for_update(LEX_SERVER_OPTIONS *server_options, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered) { DBUG_ENTER("prepare_server_struct_for_update"); altered->server_name= strdup_root(&mem, server_options->server_name); altered->server_name_length= server_options->server_name_length; DBUG_PRINT("info", ("existing name %s altered name %s", existing->server_name, altered->server_name)); /* The logic here is this: is this value set AND is it different than the existing value? */ altered->host= (server_options->host && (strcmp(server_options->host, existing->host))) ? strdup_root(&mem, server_options->host) : 0; altered->db= (server_options->db && (strcmp(server_options->db, existing->db))) ? strdup_root(&mem, server_options->db) : 0; altered->username= (server_options->username && (strcmp(server_options->username, existing->username))) ? strdup_root(&mem, server_options->username) : 0; altered->password= (server_options->password && (strcmp(server_options->password, existing->password))) ? strdup_root(&mem, server_options->password) : 0; /* port is initialised to -1, so if unset, it will be -1 */ altered->port= (server_options->port > -1 && server_options->port != existing->port) ? server_options->port : -1; altered->socket= (server_options->socket && (strcmp(server_options->socket, existing->socket))) ? strdup_root(&mem, server_options->socket) : 0; altered->scheme= (server_options->scheme && (strcmp(server_options->scheme, existing->scheme))) ? strdup_root(&mem, server_options->scheme) : 0; altered->owner= (server_options->owner && (strcmp(server_options->owner, existing->owner))) ? strdup_root(&mem, server_options->owner) : 0; DBUG_VOID_RETURN; }
static FOREIGN_SERVER * prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options) { char *unset_ptr= (char*)""; FOREIGN_SERVER *server; DBUG_ENTER("prepare_server_struct"); if (!(server= (FOREIGN_SERVER *)alloc_root(&mem, sizeof(FOREIGN_SERVER)))) DBUG_RETURN(NULL); /* purecov: inspected */ /* these two MUST be set */ if (!(server->server_name= strdup_root(&mem, server_options->server_name))) DBUG_RETURN(NULL); /* purecov: inspected */ server->server_name_length= server_options->server_name_length; if (!(server->host= server_options->host ? strdup_root(&mem, server_options->host) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ if (!(server->db= server_options->db ? strdup_root(&mem, server_options->db) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ if (!(server->username= server_options->username ? strdup_root(&mem, server_options->username) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ if (!(server->password= server_options->password ? strdup_root(&mem, server_options->password) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ /* set to 0 if not specified */ server->port= server_options->port > -1 ? server_options->port : 0; if (!(server->socket= server_options->socket ? strdup_root(&mem, server_options->socket) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ if (!(server->scheme= server_options->scheme ? strdup_root(&mem, server_options->scheme) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ if (!(server->owner= server_options->owner ? strdup_root(&mem, server_options->owner) : unset_ptr)) DBUG_RETURN(NULL); /* purecov: inspected */ DBUG_RETURN(server); }
void merge_server_struct(FOREIGN_SERVER *from, FOREIGN_SERVER *to) { DBUG_ENTER("merge_server_struct"); if (!to->host) to->host= strdup_root(&mem, from->host); if (!to->db) to->db= strdup_root(&mem, from->db); if (!to->username) to->username= strdup_root(&mem, from->username); if (!to->password) to->password= strdup_root(&mem, from->password); if (to->port == -1) to->port= from->port; if (!to->socket && from->socket) to->socket= strdup_root(&mem, from->socket); if (!to->scheme && from->scheme) to->scheme= strdup_root(&mem, from->scheme); if (!to->owner) to->owner= strdup_root(&mem, from->owner); DBUG_VOID_RETURN; }
TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from) { TYPELIB *to; uint i; if (!from) return NULL; if (!(to= (TYPELIB*) alloc_root(root, sizeof(TYPELIB)))) return NULL; if (!(to->type_names= (const char **) alloc_root(root, (sizeof(char *) + sizeof(int)) * (from->count + 1)))) return NULL; to->type_lengths= (unsigned int *)(to->type_names + from->count + 1); to->count= from->count; if (from->name) { if (!(to->name= strdup_root(root, from->name))) return NULL; } else to->name= NULL; for (i= 0; i < from->count; i++) { if (!(to->type_names[i]= strmake_root(root, from->type_names[i], from->type_lengths[i]))) return NULL; to->type_lengths[i]= from->type_lengths[i]; } to->type_names[to->count]= NULL; to->type_lengths[to->count]= 0; return to; }
static FOREIGN_SERVER *clone_server(MEM_ROOT *mem, const FOREIGN_SERVER *server, FOREIGN_SERVER *buffer) { DBUG_ENTER("sql_server.cc:clone_server"); if (!buffer) buffer= (FOREIGN_SERVER *) alloc_root(mem, sizeof(FOREIGN_SERVER)); buffer->server_name= strmake_root(mem, server->server_name, server->server_name_length); buffer->port= server->port; buffer->server_name_length= server->server_name_length; /* TODO: We need to examine which of these can really be NULL */ buffer->db= server->db ? strdup_root(mem, server->db) : NULL; buffer->scheme= server->scheme ? strdup_root(mem, server->scheme) : NULL; buffer->username= server->username? strdup_root(mem, server->username): NULL; buffer->password= server->password? strdup_root(mem, server->password): NULL; buffer->socket= server->socket ? strdup_root(mem, server->socket) : NULL; buffer->owner= server->owner ? strdup_root(mem, server->owner) : NULL; buffer->host= server->host ? strdup_root(mem, server->host) : NULL; DBUG_RETURN(buffer); }
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; DIR *dirp; struct dirent *dp; char tmp_path[FN_REFLEN+1],*tmp_file; #ifdef THREAD char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; #endif DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); #if defined(THREAD) && !defined(HAVE_READDIR_R) mysql_mutex_lock(&THR_LOCK_open); #endif dirp = opendir(directory_file_name(tmp_path,(char *) path)); #if defined(__amiga__) if ((dirp->dd_fd) < 0) /* Directory doesn't exists */ goto error; #endif if (dirp == NULL || ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; tmp_file=strend(tmp_path); #ifdef THREAD dp= (struct dirent*) dirent_tmp; #else dp=0; #endif while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp))) { if (!(finfo.name= strdup_root(names_storage, dp->d_name))) goto error; if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; bzero(finfo.mystat, sizeof(MY_STAT)); (void) strmov(tmp_file,dp->d_name); (void) my_stat(tmp_path, finfo.mystat, MyFlags); if (!(finfo.mystat->st_mode & MY_S_IREAD)) continue; } else finfo.mystat= NULL; if (push_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } (void) closedir(dirp); #if defined(THREAD) && !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_RETURN(result); error: #if defined(THREAD) && !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif my_errno=errno; if (dirp) (void) closedir(dirp); my_dirend(result); if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; #ifdef __BORLANDC__ struct ffblk find; #else struct _finddata_t find; #endif ushort mode; char tmp_path[FN_REFLEN],*tmp_file,attrib; #ifdef _WIN64 __int64 handle; #else long handle; #endif DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); /* Put LIB-CHAR as last path-character if not there */ tmp_file=tmp_path; if (!*path) *tmp_file++ ='.'; /* From current dir */ tmp_file= strnmov(tmp_file, path, FN_REFLEN-5); if (tmp_file[-1] == FN_DEVCHAR) *tmp_file++= '.'; /* From current dev-dir */ if (tmp_file[-1] != FN_LIBCHAR) *tmp_file++ =FN_LIBCHAR; tmp_file[0]='*'; /* Windows needs this !??? */ tmp_file[1]='.'; tmp_file[2]='*'; tmp_file[3]='\0'; if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; #ifdef __BORLANDC__ if ((handle= findfirst(tmp_path,&find,0)) == -1L) #else if ((handle=_findfirst(tmp_path,&find)) == -1L) #endif { DBUG_PRINT("info", ("findfirst returned error, errno: %d", errno)); if (errno != EINVAL) goto error; /* Could not read the directory, no read access. Probably because by "chmod -r". continue and return zero files in dir */ } else { do { #ifdef __BORLANDC__ attrib= find.ff_attrib; #else attrib= find.attrib; /* Do not show hidden and system files which Windows sometimes create. Note. Because Borland's findfirst() is called with the third argument = 0 hidden/system files are excluded from the search. */ if (attrib & (_A_HIDDEN | _A_SYSTEM)) continue; #endif #ifdef __BORLANDC__ if (!(finfo.name= strdup_root(names_storage, find.ff_name))) goto error; #else if (!(finfo.name= strdup_root(names_storage, find.name))) goto error; #endif if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; bzero(finfo.mystat, sizeof(MY_STAT)); #ifdef __BORLANDC__ finfo.mystat->st_size=find.ff_fsize; #else finfo.mystat->st_size=find.size; #endif mode= MY_S_IREAD; if (!(attrib & _A_RDONLY)) mode|= MY_S_IWRITE; if (attrib & _A_SUBDIR) mode|= MY_S_IFDIR; finfo.mystat->st_mode= mode; #ifdef __BORLANDC__ finfo.mystat->st_mtime= ((uint32) find.ff_ftime); #else finfo.mystat->st_mtime= ((uint32) find.time_write); #endif } else finfo.mystat= NULL; if (push_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } #ifdef __BORLANDC__ while (findnext(&find) == 0); #else while (_findnext(handle,&find) == 0); _findclose(handle); #endif } result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_PRINT("exit", ("found %d files", result->number_off_files)); DBUG_RETURN(result); error: my_errno=errno; #ifndef __BORLANDC__ if (handle != -1) _findclose(handle); #endif my_dirend(result); if (MyFlags & MY_FAE+MY_WME) my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
MY_DIR *my_dir(const char* path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; struct find_t find; ushort mode; char tmp_path[FN_REFLEN],*tmp_file,attrib; DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); /* Put LIB-CHAR as last path-character if not there */ tmp_file=tmp_path; if (!*path) *tmp_file++ ='.'; /* From current dir */ tmp_file= strmov(tmp_file,path); if (tmp_file[-1] == FN_DEVCHAR) *tmp_file++= '.'; /* From current dev-dir */ if (tmp_file[-1] != FN_LIBCHAR) *tmp_file++ =FN_LIBCHAR; tmp_file[0]='*'; /* MSDOS needs this !??? */ tmp_file[1]='.'; tmp_file[2]='*'; tmp_file[3]='\0'; if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find)) goto error; if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free((gptr) buffer,MYF(0)); goto error; } init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; do { if (!(finfo.name= strdup_root(names_storage, find.name))) goto error; if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; bzero(finfo.mystat, sizeof(MY_STAT)); finfo.mystat->st_size= find.size; mode= MY_S_IREAD; attrib= find.attrib; if (!(attrib & _A_RDONLY)) mode|= MY_S_IWRITE; if (attrib & _A_SUBDIR) mode|= MY_S_IFDIR; finfo.mystat->st_mode= mode; finfo.mystat->st_mtime= ((uint32) find.wr_date << 16) + find.wr_time; } else finfo.mystat= NULL; if (push_dynamic(dir_entries_storage, (gptr)&finfo)) goto error; } while (_dos_findnext(&find) == 0); result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_RETURN(result); error: my_dirend(result); if (MyFlags & MY_FAE+MY_WME) my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; DIR *dirp; struct dirent *dp; char tmp_path[FN_REFLEN + 2], *tmp_file; char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); #if !defined(HAVE_READDIR_R) mysql_mutex_lock(&THR_LOCK_open); #endif dirp = opendir(directory_file_name(tmp_path,(char *) path)); if (dirp == NULL || ! (buffer= my_malloc(key_memory_MY_DIR, ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), NULL, /* init_buffer */ ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(key_memory_MY_DIR, names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; tmp_file=strend(tmp_path); dp= (struct dirent*) dirent_tmp; while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp))) { if (!(finfo.name= strdup_root(names_storage, dp->d_name))) goto error; if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; memset(finfo.mystat, 0, sizeof(MY_STAT)); (void) my_stpcpy(tmp_file,dp->d_name); (void) my_stat(tmp_path, finfo.mystat, MyFlags); if (!(finfo.mystat->st_mode & MY_S_IREAD)) continue; } else finfo.mystat= NULL; if (insert_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } (void) closedir(dirp); #if !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_RETURN(result); error: #if !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif my_errno=errno; if (dirp) (void) closedir(dirp); my_dirend(result); if (MyFlags & (MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_DIR, MYF(0), path, my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno)); } DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */