/* add specified library to the list of files */ static void add_library( strarray *lib_dirs, strarray *files, const char *library ) { char *static_lib, *fullname = 0; switch(get_lib_type(lib_dirs, library, &fullname)) { case file_arh: strarray_add(files, strmake("-a%s", fullname)); break; case file_dll: strarray_add(files, strmake("-d%s", fullname)); if ((static_lib = find_static_lib(fullname))) { strarray_add(files, strmake("-a%s",static_lib)); free(static_lib); } break; case file_so: default: /* keep it anyway, the linker may know what to do with it */ strarray_add(files, strmake("-l%s", library)); break; } free(fullname); }
static char* get_temp_file(const char* prefix, const char* suffix) { int fd; char* tmp = strmake("%s-XXXXXX%s", prefix, suffix); #ifdef HAVE_SIGPROCMASK sigset_t old_set; /* block signals while manipulating the temp files list */ sigprocmask( SIG_BLOCK, &signal_mask, &old_set ); #endif fd = mkstemps( tmp, strlen(suffix) ); if (fd == -1) { /* could not create it in current directory, try in /tmp */ free(tmp); tmp = strmake("/tmp/%s-XXXXXX%s", prefix, suffix); fd = mkstemps( tmp, strlen(suffix) ); if (fd == -1) error( "could not create temp file\n" ); } close( fd ); strarray_add(tmp_files, tmp); #ifdef HAVE_SIGPROCMASK sigprocmask( SIG_SETMASK, &old_set, NULL ); #endif return tmp; }
int my_getwd(char * buf, size_t size, myf MyFlags) { char * pos; DBUG_ENTER("my_getwd"); DBUG_PRINT("my",("buf: 0x%lx size: %u MyFlags %d", (long) buf, (uint) size, MyFlags)); if (size < 1) DBUG_RETURN(-1); if (curr_dir[0]) /* Current pos is saved here */ (void) strmake(buf,&curr_dir[0],size-1); else { if (size < 2) DBUG_RETURN(-1); if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME) { char errbuf[MYSYS_STRERROR_SIZE]; my_errno=errno; my_error(EE_GETWD, MYF(ME_BELL+ME_WAITTANG), errno, my_strerror(errbuf, sizeof(errbuf), errno)); DBUG_RETURN(-1); } if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */ { pos[0]= FN_LIBCHAR; pos[1]=0; } (void) strmake(&curr_dir[0],buf, (size_t) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */
static int send_change_user_packet(MCPVIO_EXT *mpvio, const uchar *data, int data_len) { MYSQL *mysql= mpvio->mysql; char *buff, *end; int res= 1; size_t conn_attr_len= (mysql->options.extension) ? mysql->options.extension->connect_attrs_len : 0; buff= my_alloca(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); end= strmake(buff, mysql->user, USERNAME_LENGTH) + 1; if (!data_len) *end++= 0; else { if (mysql->client_flag & CLIENT_SECURE_CONNECTION) { DBUG_ASSERT(data_len <= 255); if (data_len > 255) { my_set_error(mysql, CR_MALFORMED_PACKET, SQLSTATE_UNKNOWN, 0); goto error; } *end++= data_len; } else { DBUG_ASSERT(data_len == SCRAMBLE_LENGTH_323 + 1); DBUG_ASSERT(data[SCRAMBLE_LENGTH_323] == 0); } memcpy(end, data, data_len); end+= data_len; } end= strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1; if (mysql->server_capabilities & CLIENT_PROTOCOL_41) { int2store(end, (ushort) mysql->charset->nr); end+= 2; } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; end= ma_send_connect_attr(mysql, end); res= simple_command(mysql, MYSQL_COM_CHANGE_USER, buff, (ulong)(end-buff), 1, NULL); error: my_afree(buff); return res; }
char* strarray_tostring(const strarray* arr, const char* sep) { char *str, *newstr; unsigned int i; str = strmake("%s", arr->base[0]); for (i = 1; i < arr->size; i++) { newstr = strmake("%s%s%s", str, sep, arr->base[i]); free(str); str = newstr; } return str; }
void symdirget(char *dir) { char buff[FN_REFLEN+1]; char *pos=strend(dir); if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK)) { File file; size_t length; char temp= *(--pos); /* May be "/" or "\" */ strmov(pos,".sym"); file= my_open(dir, O_RDONLY, MYF(0)); *pos++=temp; *pos=0; /* Restore old filename */ if (file >= 0) { if ((length= my_read(file, buff, sizeof(buff) - 1, MYF(0))) > 0) { for (pos= buff + length ; pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ; pos --); /* Ensure that the symlink ends with the directory symbol */ if (pos == buff || pos[-1] != FN_LIBCHAR) *pos++=FN_LIBCHAR; strmake(dir,buff, (size_t) (pos-buff)); } my_close(file, MYF(0)); } } }
void symdirget(char *dir) { char buff[FN_REFLEN]; char *pos=strend(dir); if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK)) { FILE *fp; char temp= *(--pos); /* May be "/" or "\" */ strmov(pos,".sym"); fp = my_fopen(dir, O_RDONLY,MYF(0)); *pos++=temp; *pos=0; /* Restore old filename */ if (fp) { if (fgets(buff, sizeof(buff)-1, fp)) { for (pos=strend(buff); pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ; pos --); /* Ensure that the symlink ends with the directory symbol */ if (pos == buff || pos[-1] != FN_LIBCHAR) *pos++=FN_LIBCHAR; strmake(dir,buff, (uint) (pos-buff)); } my_fclose(fp,MYF(0)); } } }
int my_realpath(char *to, const char *filename, myf MyFlags) { #if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) int result=0; char buff[BUFF_LEN]; struct stat stat_buff; DBUG_ENTER("my_realpath"); if (!(MyFlags & MY_RESOLVE_LINK) || (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode))) { char *ptr; if ((ptr=realpath(filename,buff))) strmake(to,ptr,FN_REFLEN-1); else { /* Realpath didn't work; Use original name */ my_errno=errno; if (MyFlags & MY_WME) my_error(EE_REALPATH, MYF(0), filename, my_errno); if (to != filename) strmov(to,filename); result= -1; } } DBUG_RETURN(result); #else if (to != filename) strmov(to,filename); return 0; #endif }
/* output import stubs for exported entry points that link to external symbols */ static void output_external_link_imports( DLLSPEC *spec ) { unsigned int i, pos; if (!ext_link_imports.count) return; /* nothing to do */ sort_names( &ext_link_imports ); /* get rid of duplicate names */ for (i = 1; i < ext_link_imports.count; i++) { if (!strcmp( ext_link_imports.names[i-1], ext_link_imports.names[i] )) remove_name( &ext_link_imports, i-- ); } output( "\n/* external link thunks */\n\n" ); output( "\t.data\n" ); output( "\t.align %d\n", get_alignment(get_ptr_size()) ); output( ".L__wine_spec_external_links:\n" ); for (i = 0; i < ext_link_imports.count; i++) output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.names[i]) ); output( "\n\t.text\n" ); output( "\t.align %d\n", get_alignment(get_ptr_size()) ); output( "%s:\n", asm_name("__wine_spec_external_link_thunks") ); for (i = pos = 0; i < ext_link_imports.count; i++) { char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.names[i] ); output_import_thunk( buffer, ".L__wine_spec_external_links", pos ); free( buffer ); pos += get_ptr_size(); } output_function_size( "__wine_spec_external_link_thunks" ); }
/* check if there is a static lib associated to a given dll */ static char *find_static_lib( const char *dll ) { char *lib = strmake("%s.a", dll); if (get_file_type(lib) == file_arh) return lib; free( lib ); return NULL; }
int my_setwd(const char *dir, myf MyFlags) { int res; size_t length; char *start, *pos; DBUG_ENTER("my_setwd"); DBUG_PRINT("my",("dir: '%s' MyFlags %lu", dir, MyFlags)); start=(char *) dir; if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) dir=FN_ROOTDIR; if ((res=chdir((char*) dir)) != 0) { my_errno=errno; if (MyFlags & MY_WME) my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); } else { if (test_if_hard_path(start)) { /* Hard pathname */ pos= strmake(&curr_dir[0],start,(size_t) FN_REFLEN-1); if (pos[-1] != FN_LIBCHAR) { length=(uint) (pos-(char*) curr_dir); curr_dir[length]=FN_LIBCHAR; /* must end with '/' */ curr_dir[length+1]='\0'; } } else curr_dir[0]='\0'; /* Don't save name */ } DBUG_RETURN(res); } /* my_setwd */
/* Fills in the name and exename fields */ static void extract_test (struct wine_test *test, const char *dir, int id) { BYTE* code; DWORD size; FILE* fout; int strlen, bufflen = 128; char *exepos; code = extract_rcdata (id, TESTRES, &size); if (!code) report (R_FATAL, "Can't find test resource %d: %d", id, GetLastError ()); test->name = xmalloc (bufflen); while ((strlen = LoadStringA (NULL, id, test->name, bufflen)) == bufflen - 1) { bufflen *= 2; test->name = xrealloc (test->name, bufflen); } if (!strlen) report (R_FATAL, "Can't read name of test %d.", id); test->exename = strmake (NULL, "%s/%s", dir, test->name); exepos = strstr (test->name, "_test.exe"); if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name); *exepos = 0; test->name = xrealloc (test->name, exepos - test->name + 1); report (R_STEP, "Extracting: %s", test->name); if (!(fout = fopen (test->exename, "wb")) || (fwrite (code, size, 1, fout) != 1) || fclose (fout)) report (R_FATAL, "Failed to write file %s.", test->exename); }
char *my_strerror(char *buf, size_t len, int nr) { char *msg= NULL; buf[0]= '\0'; /* failsafe */ /* These (handler-) error messages are shared by perror, as required by the principle of least surprise. */ if ((nr >= HA_ERR_FIRST) && (nr <= HA_ERR_LAST)) msg= (char *) handler_error_messages[nr - HA_ERR_FIRST]; if (msg != NULL) strmake(buf, msg, len - 1); else { /* On Windows, do things the Windows way. On a system that supports both the GNU and the XSI variant, use whichever was configured (GNU); if this choice is not advertised, use the default (POSIX/XSI). Testing for __GNUC__ is not sufficient to determine whether this choice exists. */ #if defined(__WIN__) strerror_s(buf, len, nr); #elif ((defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE >= 200112L)) || \ (defined _XOPEN_SOURCE && (_XOPEN_SOURCE >= 600))) && \ ! defined _GNU_SOURCE strerror_r(nr, buf, len); /* I can build with or without GNU */ #elif defined _GNU_SOURCE char *r= strerror_r(nr, buf, len); if (r != buf) /* Want to help, GNU? */ strmake(buf, r, len - 1); /* Then don't. */ #else strerror_r(nr, buf, len); #endif } /* strerror() return values are implementation-dependent, so let's be pragmatic. */ if (!buf[0]) strmake(buf, "unknown error", len - 1); return buf; }
int my_getwd(my_string buf, uint size, myf MyFlags) { my_string pos; DBUG_ENTER("my_getwd"); DBUG_PRINT("my",("buf: 0x%lx size: %d MyFlags %d", buf,size,MyFlags)); #if ! defined(MSDOS) if (curr_dir[0]) /* Current pos is saved here */ VOID(strmake(buf,&curr_dir[0],size-1)); else #endif { #if defined(HAVE_GETCWD) if (!getcwd(buf,size-2) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); return(-1); } #elif defined(HAVE_GETWD) { char pathname[MAXPATHLEN]; getwd(pathname); strmake(buf,pathname,size-1); } #elif defined(VMS) if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); return(-1); } intern_filename(buf,buf); #else #error "No way to get current directory" #endif if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */ { pos[0]= FN_LIBCHAR; pos[1]=0; } (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */
char *convert_dirname(char *to, const char *from, const char *from_end) { char *to_org=to; #ifdef BACKSLASH_MBTAIL CHARSET_INFO *fs= fs_character_set(); #endif /* We use -2 here, becasue we need place for the last FN_LIBCHAR */ if (!from_end || (from_end - from) > FN_REFLEN-2) from_end=from+FN_REFLEN -2; #if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2) { for (; from != from_end && *from ; from++) { if (*from == '/') *to++= FN_LIBCHAR; #ifdef FN_C_BEFORE_DIR_2 else if (*from == FN_C_BEFORE_DIR_2) *to++= FN_C_BEFORE_DIR; else if (*from == FN_C_AFTER_DIR_2) *to++= FN_C_AFTER_DIR; #endif else { #ifdef BACKSLASH_MBTAIL uint l; if (use_mb(fs) && (l= my_ismbchar(fs, from, from + 3))) { memmove(to, from, l); to+= l; from+= l - 1; to_org= to; /* Don't look inside mbchar */ } else #endif { *to++= *from; } } } *to=0; } #else /* This is ok even if to == from, becasue we need to cut the string */ to= strmake(to, from, (uint) (from_end-from)); #endif /* Add FN_LIBCHAR to the end of directory path */ if (to != to_org && (to[-1] != FN_LIBCHAR && to[-1] != FN_DEVCHAR)) { *to++=FN_LIBCHAR; *to=0; } return to; /* Pointer to end of dir */ } /* convert_dirname */
/******************************************************************* * parse_spec_export * * Parse an exported function definition in a .spec file. */ static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec ) { const char *token; int is_win32 = (spec->type == SPEC_WIN32) || (odp->flags & FLAG_EXPORT32); if (!is_win32 && odp->type == TYPE_STDCALL) { error( "'stdcall' not supported for Win16\n" ); return 0; } if (!is_win32 && odp->type == TYPE_THISCALL) { error( "'thiscall' not supported for Win16\n" ); return 0; } if (is_win32 && odp->type == TYPE_PASCAL) { error( "'pascal' not supported for Win32\n" ); return 0; } if (!parse_spec_arguments( odp, spec, 0 )) return 0; if (odp->type == TYPE_VARARGS) odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */ if (!(token = GetToken(1))) { if (!strcmp( odp->name, "@" )) { error( "Missing handler name for anonymous function\n" ); return 0; } odp->link_name = xstrdup( odp->name ); } else { odp->link_name = xstrdup( token ); if (strchr( odp->link_name, '.' )) { if (!is_win32) { error( "Forwarded functions not supported for Win16\n" ); return 0; } odp->flags |= FLAG_FORWARD; } } if (target_cpu == CPU_x86 && odp->type == TYPE_THISCALL && !(odp->flags & FLAG_FORWARD)) { char *link_name = strmake( "__thiscall_%s", odp->link_name ); free( odp->link_name ); odp->link_name = link_name; } return 1; }
int my_getwd(char * buf, size_t size, myf MyFlags) { char * pos; DBUG_ENTER("my_getwd"); DBUG_PRINT("my",("buf: 0x%lx size: %u MyFlags %lu", (long) buf, (uint) size, MyFlags)); if (size < 1) DBUG_RETURN(-1); if (curr_dir[0]) /* Current pos is saved here */ (void) strmake(buf,&curr_dir[0],size-1); else { #if defined(HAVE_GETCWD) if (size < 2) DBUG_RETURN(-1); if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME) { my_errno=errno; my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); DBUG_RETURN(-1); } #elif defined(HAVE_GETWD) { char pathname[MAXPATHLEN]; getwd(pathname); strmake(buf,pathname,size-1); } #else #error "No way to get current directory" #endif if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */ { pos[0]= FN_LIBCHAR; pos[1]=0; } (void) strmake(&curr_dir[0],buf, (size_t) (FN_REFLEN-1)); } DBUG_RETURN(0); } /* my_getwd */
/** * Read a tag segment with sorting. * * @param[in] gtop #GTOP structure <br> * Output: @CODE{gtop->gtp_array} segment table <br> * Output: @CODE{gtop->gtp_count} segment table size <br> * Output: @CODE{gtop->gtp_index} segment table index (initial value = 0) <br> * Output: @CODE{gtop->cur_tagname} current tag name * * A segment is a set of tag records which have same tag name. <br> * This function read a segment from tag file, sort it and put it on segment table. <br> * This function can treat both of standard format and compact format. * * Sorting is done by three keys. * - 1st key: tag name * - 2nd key: file name * - 3rd key: line number * * Since all records in a segment have same tag name, you need not think about 1st key. */ void segment_read(GTOP *gtop) { const char *tagline, *fid, *path, *lineno; GTP *gtp; struct sh_entry *sh; /* * Save tag lines. */ gtop->cur_tagname[0] = '\0'; while ((tagline = dbop_next(gtop->dbop)) != NULL) { VIRTUAL_GRTAGS_GSYMS_PROCESSING(gtop); /* * get tag name and line number. * * tagline = <file id> <tag name> <line number> */ if (gtop->cur_tagname[0] == '\0') { strlimcpy(gtop->cur_tagname, gtop->dbop->lastkey, sizeof(gtop->cur_tagname)); } else if (strcmp(gtop->cur_tagname, gtop->dbop->lastkey) != 0) { /* * Dbop_next() wil read the same record again. */ dbop_unread(gtop->dbop); break; } gtp = varray_append(gtop->vb); gtp->tagline = pool_strdup(gtop->segment_pool, tagline, 0); gtp->tag = (const char *)gtop->cur_tagname; /* * convert fid into hashed path name to save memory. */ fid = (const char *)strmake(tagline, " "); path = gpath_fid2path(fid, NULL); if (path == NULL) die("gtags_first: path not found. (fid=%s)", fid); sh = strhash_assign(gtop->path_hash, path, 1); gtp->path = sh->name; lineno = seekto(gtp->tagline, SEEKTO_LINENO); if (lineno == NULL) die("illegal tag record.\n%s", tagline); gtp->lineno = atoi(lineno); } /* * Sort tag lines. */ gtop->gtp_array = varray_assign(gtop->vb, 0, 0); gtop->gtp_count = gtop->vb->length; gtop->gtp_index = 0; if (!(gtop->flags & GTOP_NOSORT)) qsort(gtop->gtp_array, gtop->gtp_count, sizeof(GTP), compare_tags); }
const char *my_thread_name(void) { char name_buff[100]; struct st_my_thread_var *tmp=my_thread_var; if (!tmp->name[0]) { my_thread_id id= my_thread_dbug_id(); sprintf(name_buff,"T@%lu", (ulong) id); strmake(tmp->name,name_buff,THREAD_NAME_SIZE); } return tmp->name; }
/******************************************************************* * get_callfrom16_name */ static const char *get_callfrom16_name( const ORDDEF *odp ) { static char *buffer; free( buffer ); buffer = strmake( "%s_%s_%s", (odp->type == TYPE_PASCAL) ? "p" : (odp->type == TYPE_VARARGS) ? "v" : "c", (odp->flags & FLAG_REGISTER) ? "regs" : (odp->flags & FLAG_RET16) ? "word" : "long", get_args_str(odp) ); return buffer; }
static void run_test (struct wine_test* test, const char* subtest) { int status; const char* file = get_test_source_file(test->name, subtest); const char* rev = get_file_rev(file); char *cmd = strmake (NULL, "%s %s", test->exename, subtest); xprintf ("%s:%s start %s %s\n", test->name, subtest, file, rev); status = run_ex (cmd, NULL, 120000); free (cmd); xprintf ("%s:%s done (%d)\n", test->name, subtest, status); }
char *convert_dirname(char *to, const char *from, const char *from_end) { char *to_org=to; #ifdef _WIN32 CHARSET_INFO *fs= fs_character_set(); #endif DBUG_ENTER("convert_dirname"); /* We use -2 here, becasue we need place for the last FN_LIBCHAR */ if (!from_end || (from_end - from) > FN_REFLEN-2) from_end=from+FN_REFLEN -2; #if FN_LIBCHAR != '/' { for (; from != from_end && *from ; from++) { if (*from == '/') *to++= FN_LIBCHAR; else { #ifdef _WIN32 uint l; if (use_mb(fs) && (l= my_ismbchar(fs, from, from + 3))) { memmove(to, from, l); to+= l; from+= l - 1; to_org= to; /* Don't look inside mbchar */ } else #endif { *to++= *from; } } } *to=0; } #else /* This is ok even if to == from, becasue we need to cut the string */ to= strmake(to, from, (size_t) (from_end-from)); #endif /* Add FN_LIBCHAR to the end of directory path */ if (to != to_org && (to[-1] != FN_LIBCHAR && to[-1] != FN_DEVCHAR)) { *to++=FN_LIBCHAR; *to=0; } DBUG_RETURN(to); /* Pointer to end of dir */ } /* convert_dirname */
static char* try_lib_path(const char* dir, const char* pre, const char* library, const char* ext, file_type expected_type) { char *fullname; file_type type; /* first try a subdir named from the library we are looking for */ fullname = strmake("%s/%s/%s%s%s", dir, library, pre, library, ext); if (verbose > 1) fprintf(stderr, "Try %s...", fullname); type = get_file_type(fullname); if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n"); if (type == expected_type) return fullname; free( fullname ); fullname = strmake("%s/%s%s%s", dir, pre, library, ext); if (verbose > 1) fprintf(stderr, "Try %s...", fullname); type = get_file_type(fullname); if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n"); if (type == expected_type) return fullname; free( fullname ); return 0; }
/** * readrecord: read recoed indexed by label. * * @param[in] label label in config file * @return record or NULL * * Jobs: * - skip comment. * - append following line. * - format check. */ static const char * readrecord(FILE *fp, const char *label) { char *p; int flag = STRBUF_NOCRLF|STRBUF_SHARPSKIP; int count = 0; rewind(fp); while ((p = strbuf_fgets(ib, fp, flag)) != NULL) { count++; /* * ignore \<new line>. */ flag &= ~STRBUF_APPEND; if (*p == '\0') continue; if (strbuf_unputc(ib, '\\')) { flag |= STRBUF_APPEND; continue; } trim(p); for (;;) { const char *candidate; /* * pick up candidate. */ if ((candidate = strmake(p, "|:")) == NULL) die("invalid config file format (line %d).", count); if (!strcmp(label, candidate)) { if (!(p = locatestring(p, ":", MATCH_FIRST))) die("invalid config file format (line %d).", count); return check_strdup(p); } /* * locate next candidate. */ p += strlen(candidate); if (*p == ':') break; else if (*p == '|') p++; else die("invalid config file format (line %d).", count); } } /* * config line not found. */ return NULL; }
int my_setwd(const char *dir, myf MyFlags) { int res; size_t length; char *start, *pos; #if defined(VMS) char buff[FN_REFLEN]; #endif DBUG_ENTER("my_setwd"); DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); start=(char *) dir; if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) dir=FN_ROOTDIR; #ifdef VMS { pos=strmov(buff,dir); if (pos[-1] != FN_LIBCHAR) { pos[0]=FN_LIBCHAR; /* Mark as directory */ pos[1]=0; } system_filename(buff,buff); /* Change to VMS format */ dir=buff; } #endif /* VMS */ if ((res=chdir((char*) dir)) != 0) { my_errno=errno; if (MyFlags & MY_WME) my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); } else { if (test_if_hard_path(start)) { /* Hard pathname */ pos= strmake(&curr_dir[0],start,(size_t) FN_REFLEN-1); if (pos[-1] != FN_LIBCHAR) { length=(uint) (pos-(char*) curr_dir); curr_dir[length]=FN_LIBCHAR; /* must end with '/' */ curr_dir[length+1]='\0'; } } else curr_dir[0]='\0'; /* Don't save name */ } DBUG_RETURN(res); } /* my_setwd */
int spawn(const strarray* prefix, const strarray* args, int ignore_errors) { unsigned int i; int status; strarray* arr = strarray_dup(args); const char** argv; char* prog = 0; strarray_add(arr, NULL); argv = arr->base; if (prefix) { const char *p = strrchr(argv[0], '/'); if (!p) p = argv[0]; else p++; for (i = 0; i < prefix->size; i++) { struct stat st; free( prog ); prog = strmake("%s/%s%s", prefix->base[i], p, EXEEXT); if (stat(prog, &st) == 0 && S_ISREG(st.st_mode) && (st.st_mode & 0111)) { argv[0] = prog; break; } } } if (verbose) { for(i = 0; argv[i]; i++) printf("%s ", argv[i]); printf("\n"); } if ((status = _spawnvp( _P_WAIT, argv[0], argv)) && !ignore_errors) { if (status > 0) error("%s failed\n", argv[0]); else perror("winegcc"); exit(3); } free(prog); strarray_free(arr); return status; }
/* open the .so library for a given dll in a specified path */ static char *try_library_path( const char *path, const char *name ) { char *buffer; int fd; buffer = strmake( "%s/lib%s.def", path, name ); /* check if the file exists */ if ((fd = open( buffer, O_RDONLY )) != -1) { close( fd ); return buffer; } free( buffer ); return NULL; }
my_bool init_tmpdir(MY_TMPDIR *tmpdir, const char *pathlist) { char *end, *copy; char buff[FN_REFLEN]; DBUG_ENTER("init_tmpdir"); DBUG_PRINT("enter", ("pathlist: %s", pathlist ? pathlist : "NULL")); mysql_mutex_init(key_TMPDIR_mutex, &tmpdir->mutex, MY_MUTEX_INIT_FAST); if (my_init_dynamic_array(&tmpdir->full_list, sizeof(char*), 1, 5)) goto err; if (!pathlist || !pathlist[0]) { /* Get default temporary directory */ pathlist=getenv("TMPDIR"); /* Use this if possible */ #if defined(_WIN32) if (!pathlist) pathlist=getenv("TEMP"); if (!pathlist) pathlist=getenv("TMP"); #endif if (!pathlist || !pathlist[0]) pathlist=(char*) P_tmpdir; } do { size_t length; end=strcend(pathlist, DELIM); strmake(buff, pathlist, (uint) (end-pathlist)); length= cleanup_dirname(buff, buff); if (!(copy= my_strndup(key_memory_MY_TMPDIR_full_list, buff, length, MYF(MY_WME))) || insert_dynamic(&tmpdir->full_list, ©)) DBUG_RETURN(TRUE); pathlist=end+1; } while (*end); freeze_size(&tmpdir->full_list); tmpdir->list=(char **)tmpdir->full_list.buffer; tmpdir->max=tmpdir->full_list.elements-1; tmpdir->cur=0; DBUG_RETURN(FALSE); err: delete_dynamic(&tmpdir->full_list); /* Safe to free */ mysql_mutex_destroy(&tmpdir->mutex); DBUG_RETURN(TRUE); }
char *convert_dirname(char *to, const char *from, const char *from_end) { char *to_org=to; /* We use -2 here, becasue we need place for the last FN_LIBCHAR */ if (!from_end || (from_end - from) > FN_REFLEN-2) from_end=from+FN_REFLEN -2; #if FN_LIBCHAR != '/' || defined(FN_C_BEFORE_DIR_2) { for (; *from && from != from_end; from++) { if (*from == '/') *to++= FN_LIBCHAR; #ifdef FN_C_BEFORE_DIR_2 else if (*from == FN_C_BEFORE_DIR_2) *to++= FN_C_BEFORE_DIR; else if (*from == FN_C_AFTER_DIR_2) *to++= FN_C_AFTER_DIR; #endif else *to++= *from; } *to=0; } #else /* This is ok even if to == from, becasue we need to cut the string */ to= strmake(to, from, (uint) (from_end-from)); #endif /* Add FN_LIBCHAR to the end of directory path */ if (to != to_org && (to[-1] != FN_LIBCHAR && to[-1] != FN_DEVCHAR)) { *to++=FN_LIBCHAR; *to=0; } #ifdef FN_UPPER_CASE caseup_str(to_org); #endif #ifdef FN_LOWER_CASE casedn_str(to_org); #endif return to; /* Pointer to end of dir */ } /* convert_dirname */
char *get_charsets_dir(char *buf) { const char *sharedir= SHAREDIR; char *res; DBUG_ENTER("get_charsets_dir"); if (charsets_dir != NULL) strmake(buf, charsets_dir, FN_REFLEN-1); else { if (test_if_hard_path(sharedir) || is_prefix(sharedir, DEFAULT_CHARSET_HOME)) strxmov(buf, sharedir, "/", CHARSET_DIR, NullS); else strxmov(buf, DEFAULT_CHARSET_HOME, "/", sharedir, "/", CHARSET_DIR, NullS); } res= convert_dirname(buf,buf,NullS); DBUG_PRINT("info",("charsets dir: '%s'", buf)); DBUG_RETURN(res); }