13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include "drizzled/internal/my_sys.h"
22
#ifdef HAVE_SYS_STAT_H
23
# include <sys/stat.h>
28
#include "drizzled/internal/m_string.h"
16
#include "mysys_priv.h"
17
#include <mystrings/m_string.h>
38
20
Formats a filename with possible replace of directory of extension
60
42
else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
62
44
/* Put 'dir' before the given path */
63
strncpy(buff,dev,sizeof(buff)-1);
45
strmake(buff,dev,sizeof(buff)-1);
64
46
pos=convert_dirname(dev,dir,NULL);
65
strncpy(pos,buff,sizeof(buff)-1- (int) (pos-dev));
47
strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
50
if (flag & MY_PACK_FILENAME)
51
pack_dirname(dev,dev); /* Put in ./.. and ~/.. */
68
52
if (flag & MY_UNPACK_FILENAME)
69
53
(void) unpack_dirname(dev,dev); /* Replace ~/.. with dir */
95
79
if (flag & MY_SAFE_PATH)
97
tmp_length= min(strlength(startpos), (size_t)(FN_REFLEN-1));
98
strncpy(to,startpos,tmp_length);
81
tmp_length= strlength(startpos);
82
(void) strmake(to,startpos,cmin(tmp_length,FN_REFLEN-1));
103
86
if (to == startpos)
105
memmove(buff, name, length); /* Save name for last copy */
88
memcpy(buff, name, length); /* Save name for last copy */
108
char *tmp= strcpy(to, dev) + strlen(dev);
109
pos= strncpy(tmp,name,length) + length;
110
(void) strcpy(pos,ext); /* Don't convert extension */
91
pos=strmake(my_stpcpy(to,dev),name,length);
92
(void) my_stpcpy(pos,ext); /* Don't convert extension */
113
95
If MY_RETURN_REAL_PATH and MY_RESOLVE_SYMLINK is given, only do
114
96
realpath if the file is a symbolic link
116
98
if (flag & MY_RETURN_REAL_PATH)
118
struct stat stat_buff;
119
char rp_buff[PATH_MAX];
120
if ((!flag & MY_RESOLVE_SYMLINKS) ||
121
(!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
123
if (!realpath(to,rp_buff))
124
my_load_path(rp_buff, to, NULL);
125
rp_buff[FN_REFLEN-1]= '\0';
99
(void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ?
100
MY_RESOLVE_LINK: 0));
129
101
else if (flag & MY_RESOLVE_SYMLINKS)
132
ssize_t sym_link_size= readlink(buff,to,FN_REFLEN-1);
133
if (sym_link_size >= 0)
134
to[sym_link_size]= '\0';
104
(void) my_readlink(to, buff, MYF(0));
137
107
} /* fn_format */