12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18
#include <drizzled/internal/my_sys.h>
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include <mystrings/m_string.h>
18
#include "my_static.h"
22
#include <drizzled/internal/m_string.h>
23
#include "my_static.h"
30
23
static char * expand_tilde(char * *path);
31
static size_t system_filename(char * to, const char *from);
25
/* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */
26
/* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */
27
/* to may be == from */
29
void pack_dirname(char * to, const char *from)
32
size_t d_length,length,buff_length= 0;
36
(void) intern_filename(to,from); /* Change to intern name */
39
if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skip device part */
45
if (!(getcwd(buff, FN_REFLEN)))
48
buff_length= strlen(buff);
49
d_length= (size_t) (start-to);
51
(buff_length == d_length && !memcmp(buff,start,d_length))) &&
52
*start != FN_LIBCHAR && *start)
53
{ /* Put current dir before */
54
bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
58
if ((d_length= cleanup_dirname(to,to)) != 0)
63
length= strlen(home_dir);
64
if (home_dir[length-1] == FN_LIBCHAR)
65
length--; /* Don't test last '/' */
67
if (length > 1 && length < d_length)
68
{ /* test if /xx/yy -> ~/yy */
69
if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
71
to[0]=FN_HOMELIB; /* Filename begins with ~ */
72
(void) strcpy(to+1,to+length);
76
{ /* Test if cwd is ~/... */
77
if (length > 1 && length < buff_length)
79
if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
82
(void) strcpy(buff+1,buff+length);
85
if (is_prefix(to,buff))
89
(void) strcpy(to,to+length); /* Remove everything before */
92
to[0]= FN_CURLIB; /* Put ./ instead of cwd */
34
104
remove unwanted chars from dirname
50
120
# length of new name
53
static size_t cleanup_dirname(char *to, const char *from)
123
size_t cleanup_dirname(register char *to, const char *from)
57
const char * from_ptr;
125
register size_t length;
127
register const char * from_ptr;
128
register char * start;
59
129
char parent[5], /* for "FN_PARENTDIR" */
60
130
buff[FN_REFLEN+1],*end_parentdir;
131
#ifdef BACKSLASH_MBTAIL
132
CHARSET_INFO *fs= fs_character_set();
165
238
bool my_use_symdir=0; /* Set this if you want to use symdirs */
241
void symdirget(char *dir)
243
char buff[FN_REFLEN];
244
char *pos= strchr(dir, '\0');
245
if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
249
char temp= *(--pos); /* May be "/" or "\" */
251
file= my_open(dir, O_RDONLY, MYF(0));
252
*pos++=temp; *pos=0; /* Restore old filename */
255
if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0)
257
for (pos= buff + length ;
258
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
261
/* Ensure that the symlink ends with the directory symbol */
262
if (pos == buff || pos[-1] != FN_LIBCHAR)
265
strncpy(dir,buff, FN_REFLEN-1);
267
my_close(file, MYF(0));
271
#endif /* USE_SYMDIR */
169
275
Fixes a directroy name so that can be used by open()
232
342
if (path[0][0] == FN_LIBCHAR)
233
343
return home_dir; /* ~/ expanded to home */
235
struct passwd *user_entry;
347
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;
349
if (!(str=strchr(*path,FN_LIBCHAR)))
350
str= strchr(*path, '\0');
351
save= *str; *str= '\0';
352
user_entry=getpwnam(*path);
358
return user_entry->pw_dir;
288
402
/* Used before system command's like open(), create() .. */
289
403
/* Returns used length of to; total length should be FN_REFLEN */
291
static size_t system_filename(char * to, const char *from)
405
size_t system_filename(char * to, const char *from)
407
#ifndef FN_C_BEFORE_DIR
293
408
return strlen(strncpy(to,from,FN_REFLEN-1));
411
/* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
412
/* change 'dev:xxx' to 'dev:xxx' */
413
/* change './xxx' to 'xxx' */
414
/* change './lib/' or lib/ to '[.lib]' */
415
/* change '/x/y/z to '[x.y]x' */
416
/* change 'dev:/x' to 'dev:[000000]x' */
420
char * to_pos,from_pos,pos;
421
char buff[FN_REFLEN];
424
(void) strcpy(buff,from); /* If to == from */
426
if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
429
to_pos= strncpy(to,from_pos,(size_t) (pos-from_pos));
436
if (from_pos[0] == FN_CURLIB && from_pos[1] == FN_LIBCHAR)
437
from_pos+=2; /* Skip './' */
438
if (strchr(from_pos,FN_LIBCHAR))
440
*(to_pos++) = FN_C_BEFORE_DIR;
441
if (strstr(from_pos,FN_ROOTDIR) == from_pos)
443
from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */
444
if (! strchr(from_pos,FN_LIBCHAR))
445
{ /* No dir, use [000000] */
446
to_pos= strcpy(to_pos,FN_C_ROOT_DIR)+strlen(FN_C_ROOT_DIR);
451
*(to_pos++)=FN_C_DIR_SEP; /* '.' gives current dir */
453
while ((pos=strchr(from_pos,FN_LIBCHAR)))
456
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
457
if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
458
from_pos+strlen(FN_PARENTDIR) == pos) {
459
to_pos= strcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
460
to_pos+= strlen(FN_C_PARENT_DIR);
464
to_pos= strncpy(to_pos,from_pos,(size_t) (pos-from_pos));
465
to_pos+= strlen(to_pos);
469
*(to_pos++)=FN_C_AFTER_DIR;
472
strcpy(to_pos, from_pos);
294
476
} /* system_filename */