45
if (!(getcwd(buff, FN_REFLEN)))
50
if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0))))
48
52
buff_length= strlen(buff);
49
53
d_length= (size_t) (start-to);
50
54
if ((start == to ||
51
(buff_length == d_length && !memcmp(buff,start,d_length))) &&
52
*start != FN_LIBCHAR && *start)
55
(buff_length == d_length && !memcmp(buff,start,d_length))) &&
56
*start != FN_LIBCHAR && *start)
53
57
{ /* Put current dir before */
54
bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
58
bchange((uchar*) to, d_length, (uchar*) buff, buff_length, strlen(to)+1);
63
67
length= strlen(home_dir);
64
68
if (home_dir[length-1] == FN_LIBCHAR)
65
length--; /* Don't test last '/' */
69
length--; /* Don't test last '/' */
67
71
if (length > 1 && length < d_length)
68
72
{ /* test if /xx/yy -> ~/yy */
69
73
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);
75
to[0]=FN_HOMELIB; /* Filename begins with ~ */
76
(void) strmov_overlapp(to+1,to+length);
76
80
{ /* Test if cwd is ~/... */
77
81
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);
83
if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
86
(void) strmov_overlapp(buff+1,buff+length);
85
89
if (is_prefix(to,buff))
89
(void) strcpy(to,to+length); /* Remove everything before */
92
to[0]= FN_CURLIB; /* Put ./ instead of cwd */
93
(void) strmov_overlapp(to,to+length); /* Remove everything before */
96
to[0]= FN_CURLIB; /* Put ./ instead of cwd */
138
142
if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
139
143
{ /* Skip device part */
140
144
length=(size_t) (pos-from_ptr)+1;
141
start= strncpy(buff,from_ptr,length);
142
start+= strlen(from_ptr);
145
start=stpncpy(buff,from_ptr,length); from_ptr+=length;
147
149
parent[0]=FN_LIBCHAR;
148
length= (size_t)((strcpy(parent+1,FN_PARENTDIR)+strlen(FN_PARENTDIR))-parent);
150
length=(size_t) (stpcpy(parent+1,FN_PARENTDIR)-parent);
149
151
for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
151
153
#ifdef BACKSLASH_MBTAIL
153
155
if (use_mb(fs) && (l= my_ismbchar(fs, from_ptr - 1, from_ptr + 2)))
155
157
for (l-- ; l ; *++pos= *from_ptr++, l--);
175
177
pos+=length+1; /* Don't unpack ~/.. */
178
pos= strcpy(buff,home_dir)+strlen(home_dir)-1; /* Unpacks ~/.. */
180
pos=stpcpy(buff,home_dir)-1; /* Unpacks ~/.. */
179
181
if (*pos == FN_LIBCHAR)
180
182
pos--; /* home ended with '/' */
182
184
if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR))
184
if (getcwd(curr_dir,FN_REFLEN))
186
if (my_getwd(curr_dir,FN_REFLEN,MYF(0)))
186
188
pos+=length+1; /* Don't unpack ./.. */
189
pos= strcpy(buff,curr_dir)+strlen(curr_dir)-1; /* Unpacks ./.. */
191
pos=stpcpy(buff,curr_dir)-1; /* Unpacks ./.. */
190
192
if (*pos == FN_LIBCHAR)
191
193
pos--; /* home ended with '/' */
196
198
if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0)
197
199
{ /* Don't remove ~user/ */
198
pos= strcpy(end_parentdir+1,parent)+strlen(parent);
200
pos=stpcpy(end_parentdir+1,parent);
224
(void) strcpy(to,buff);
226
(void) stpcpy(to,buff);
225
227
return((size_t) (pos-buff));
226
228
} /* cleanup_dirname */
230
232
On system where you don't have symbolic links, the following
231
code will allow you to create a file:
233
code will allow you to create a file:
232
234
directory-name.sym that should contain the real path
233
235
to the directory. This will be used if the directory name
249
251
char temp= *(--pos); /* May be "/" or "\" */
251
253
file= my_open(dir, O_RDONLY, MYF(0));
252
254
*pos++=temp; *pos=0; /* Restore old filename */
255
257
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);
259
for (pos= buff + length ;
260
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
263
/* Ensure that the symlink ends with the directory symbol */
264
if (pos == buff || pos[-1] != FN_LIBCHAR)
267
strmake(dir,buff, (size_t) (pos-buff));
267
269
my_close(file, MYF(0));
319
321
if (tilde_expansion[h_length-1] == FN_LIBCHAR)
321
323
if (buff+h_length < suffix)
322
memmove(buff+h_length, suffix, length);
324
memcpy(buff+h_length, suffix, length);
324
bmove_upp((unsigned char*) buff+h_length+length, (unsigned char*) suffix+length, length);
325
memmove(buff, tilde_expansion, h_length);
326
bmove_upp((uchar*) buff+h_length+length, (uchar*) suffix+length, length);
327
memcpy(buff, tilde_expansion, h_length);
389
391
n_length=unpack_dirname(buff,buff);
390
392
if (n_length+strlen(from+length) < FN_REFLEN)
392
(void) strcpy(buff+n_length,from+length);
394
(void) stpcpy(buff+n_length,from+length);
393
395
length= system_filename(to,buff); /* Fix to usably filename */
405
407
size_t system_filename(char * to, const char *from)
407
409
#ifndef FN_C_BEFORE_DIR
408
return strlen(strncpy(to,from,FN_REFLEN-1));
410
return (size_t) (strmake(to,from,FN_REFLEN-1)-to);
411
413
/* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
421
423
char buff[FN_REFLEN];
424
(void) strcpy(buff,from); /* If to == from */
426
(void) stpcpy(buff,from); /* If to == from */
426
428
if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
429
to_pos= strncpy(to,from_pos,(size_t) (pos-from_pos));
431
to_pos=stpncpy(to,from_pos,(size_t) (pos-from_pos));
443
444
from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */
444
445
if (! strchr(from_pos,FN_LIBCHAR))
445
446
{ /* No dir, use [000000] */
446
to_pos= strcpy(to_pos,FN_C_ROOT_DIR)+strlen(FN_C_ROOT_DIR);
447
to_pos=stpcpy(to_pos,FN_C_ROOT_DIR);
453
454
while ((pos=strchr(from_pos,FN_LIBCHAR)))
455
456
if (libchar_found++)
456
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
457
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
457
458
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);
459
from_pos+strlen(FN_PARENTDIR) == pos)
460
to_pos=stpcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
464
to_pos= strncpy(to_pos,from_pos,(size_t) (pos-from_pos));
465
to_pos+= strlen(to_pos);
462
to_pos=stpncpy(to_pos,from_pos,(size_t) (pos-from_pos));
469
465
*(to_pos++)=FN_C_AFTER_DIR;
472
strcpy(to_pos, from_pos);
467
length= (size_t) (stpcpy(to_pos,from_pos)-to);
476
470
} /* system_filename */
484
478
char buff[FN_REFLEN];
486
480
{ /* Dirname may destroy from */
490
484
length= dirname_part(to, from, &to_length); /* Copy dirname & fix chars */
491
(void) strcpy(to + to_length,from+length);
485
(void) stpcpy(to + to_length,from+length);
493
487
} /* intern_filename */