18 #include <drizzled/internal/my_sys.h>
22 #include <drizzled/internal/m_string.h>
23 #include "my_static.h"
30 static char * expand_tilde(
char * *path);
31 static size_t system_filename(
char * to,
const char *from);
53 static size_t cleanup_dirname(
char *to,
const char *from)
57 const char * from_ptr;
60 buff[FN_REFLEN+1],*end_parentdir;
65 if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
67 length=(size_t) (pos-from_ptr)+1;
68 start= strncpy(buff,from_ptr,length);
69 start+= strlen(from_ptr);
75 length= (size_t)((strcpy(parent+1,FN_PARENTDIR)+strlen(FN_PARENTDIR))-parent);
76 for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
78 #ifdef BACKSLASH_MBTAIL
80 if (use_mb(fs) && (l= my_ismbchar(fs, from_ptr - 1, from_ptr + 2)))
82 for (l-- ; l ; *++pos= *from_ptr++, l--);
89 if (*pos == FN_LIBCHAR)
91 if ((
size_t) (pos-start) > length &&
92 memcmp(pos-length,parent,length) == 0)
98 if (*pos == FN_HOMELIB && (pos == start || pos[-1] == FN_LIBCHAR))
105 pos= strcpy(buff,home_dir)+strlen(home_dir)-1;
106 if (*pos == FN_LIBCHAR)
109 if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR))
111 if (getcwd(curr_dir,FN_REFLEN))
116 pos= strcpy(buff,curr_dir)+strlen(curr_dir)-1;
117 if (*pos == FN_LIBCHAR)
121 while (pos >= start && *pos != FN_LIBCHAR)
123 if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0)
125 pos= strcpy(end_parentdir+1,parent)+strlen(parent);
131 else if ((
size_t) (pos-start) == length-1 &&
132 !memcmp(start,parent+1,length-1))
134 else if (pos-start > 0 && pos[-1] == FN_LIBCHAR)
136 #ifdef FN_NETWORK_DRIVES
141 else if (pos-start > 1 && pos[-1] == FN_CURLIB && pos[-2] == FN_LIBCHAR)
143 else if (pos > buff+1 && pos[-1] == FN_HOMELIB && pos[-2] == FN_LIBCHAR)
147 start=buff; pos=buff+1;
151 (void) strcpy(to,buff);
152 return((
size_t) (pos-buff));
165 bool my_use_symdir=0;
187 size_t unpack_dirname(
char * to,
const char *from)
189 size_t length, h_length;
190 char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
192 (void) intern_filename(buff,from);
193 length= strlen(buff);
196 buff[length-1] != FN_DEVCHAR &&
198 buff[length-1] != FN_LIBCHAR && buff[length-1] !=
'/')
200 buff[length]=FN_LIBCHAR;
201 buff[length+1]=
'\0';
204 length=cleanup_dirname(buff,buff);
205 if (buff[0] == FN_HOMELIB)
207 suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
210 length-= (size_t) (suffix-buff)-1;
211 if (length+(h_length= strlen(tilde_expansion)) <= FN_REFLEN)
213 if (tilde_expansion[h_length-1] == FN_LIBCHAR)
215 if (buff+h_length < suffix)
216 memmove(buff+h_length, suffix, length);
218 bmove_upp((
unsigned char*) buff+h_length+length, (
unsigned char*) suffix+length, length);
219 memmove(buff, tilde_expansion, h_length);
223 return(system_filename(to,buff));
230 static char * expand_tilde(
char * *path)
232 if (path[0][0] == FN_LIBCHAR)
235 struct passwd *user_entry;
237 if (!(str=strchr(*path,FN_LIBCHAR)))
238 str= strchr(*path,
'\0');
239 save= *str; *str=
'\0';
240 user_entry=getpwnam(*path);
246 return user_entry->pw_dir;
269 size_t unpack_filename(
char * to,
const char *from)
271 size_t length, n_length, buff_length;
272 char buff[FN_REFLEN];
274 length=dirname_part(buff, from, &buff_length);
275 n_length=unpack_dirname(buff,buff);
276 if (n_length+strlen(from+length) < FN_REFLEN)
278 (void) strcpy(buff+n_length,from+length);
279 length= system_filename(to,buff);
282 length= system_filename(to,from);
291 static size_t system_filename(
char * to,
const char *from)
293 return strlen(strncpy(to,from,FN_REFLEN-1));
299 char *intern_filename(
char *to,
const char *from)
301 size_t length, to_length;
302 char buff[FN_REFLEN];
308 length= dirname_part(to, from, &to_length);
309 (void) strcpy(to + to_length,from+length);