16 #include "mysys_priv.h"
19 static char *find_file_in_path(
char *
to,
const char *
name);
32 char * my_path(
char *
to,
const char *progname,
33 const char *own_pathname_part)
35 char *start, *end, *prog;
37 DBUG_ENTER(
"my_path");
40 if (progname && (dirname_part(to, progname, &to_length) ||
41 find_file_in_path(to,progname) ||
42 ((prog=getenv(
"_")) != 0 &&
43 dirname_part(to, prog, &to_length))))
45 (void) intern_filename(to,to);
46 if (!test_if_hard_path(to))
48 if (!my_getwd(curr_dir,FN_REFLEN,MYF(0)))
49 bchange((uchar*)
to, 0, (uchar*) curr_dir, strlen(curr_dir), strlen(to)+1);
54 if ((end = getenv(
"MY_BASEDIR_VERSION")) == 0 &&
55 (end = getenv(
"MY_BASEDIR")) == 0)
57 #ifdef DEFAULT_BASEDIR
58 end= (
char*) DEFAULT_BASEDIR;
63 (void) intern_filename(to,end);
65 if (to != start && to[-1] != FN_LIBCHAR)
67 (void) strmov(to,own_pathname_part);
69 DBUG_PRINT(
"exit",(
"to: '%s'",start));
80 #define PROGRAM_EXTENSION ".exe"
85 static char *find_file_in_path(
char *to,
const char *
name)
87 char *path,*pos,dir[2];
90 if (!(path=getenv(
"PATH")))
92 dir[0]=FN_LIBCHAR; dir[1]=0;
93 #ifdef PROGRAM_EXTENSION
95 ext=PROGRAM_EXTENSION;
98 for (pos=path ; (pos=strchr(pos,PATH_SEP)) ; path= ++pos)
102 strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS);
103 if (!access(to,F_OK))
105 to[(uint) (pos-path)+1]=0;
112 strxmov(to+1,dir,name,ext,NullS);
113 if (!access(to,F_OK))