18 #include "mysys_priv.h"
20 #include "mysys_err.h"
22 #include <sys/param.h>
46 int my_getwd(
char *
buf,
size_t size, myf MyFlags)
49 DBUG_ENTER(
"my_getwd");
50 DBUG_PRINT(
"my",(
"buf: 0x%lx size: %u MyFlags %d",
51 (
long) buf, (uint) size, MyFlags));
57 (void) strmake(buf,&curr_dir[0],size-1);
60 #if defined(HAVE_GETCWD)
63 if (!getcwd(buf,(uint) (size-2)) && MyFlags & MY_WME)
65 char errbuf[MYSYS_STRERROR_SIZE];
67 my_error(EE_GETWD, MYF(ME_BELL+ME_WAITTANG),
68 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
71 #elif defined(HAVE_GETWD)
73 char pathname[MAXPATHLEN];
75 strmake(buf,pathname,size-1);
78 #error "No way to get current directory"
80 if (*((pos=strend(buf))-1) != FN_LIBCHAR)
85 (void) strmake(&curr_dir[0],buf, (
size_t) (FN_REFLEN-1));
93 int my_setwd(
const char *dir, myf MyFlags)
98 DBUG_ENTER(
"my_setwd");
99 DBUG_PRINT(
"my",(
"dir: '%s' MyFlags %d", dir, MyFlags));
102 if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0))
104 if ((res=chdir((
char*) dir)) != 0)
107 if (MyFlags & MY_WME)
109 char errbuf[MYSYS_STRERROR_SIZE];
110 my_error(EE_SETWD, MYF(ME_BELL+ME_WAITTANG), start,
111 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
116 if (test_if_hard_path(start))
118 pos= strmake(&curr_dir[0],start,(
size_t) FN_REFLEN-1);
119 if (pos[-1] != FN_LIBCHAR)
121 length=(uint) (pos-(
char*) curr_dir);
122 curr_dir[length]=FN_LIBCHAR;
123 curr_dir[length+1]=
'\0';
137 int test_if_hard_path(
register const char *dir_name)
139 if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR)
140 return (home_dir != NullS && test_if_hard_path(home_dir));
141 if (dir_name[0] == FN_LIBCHAR)
144 return (strchr(dir_name,FN_DEVCHAR) != 0);
163 my_bool has_path(
const char *
name)
165 return test(strchr(name, FN_LIBCHAR))
166 #if FN_LIBCHAR != '/'
167 ||
test(strchr(name,
'/'))
170 ||
test(strchr(name, FN_DEVCHAR))