16 #include "mysys_priv.h"
26 char * fn_format(
char *
to,
const char *
name,
const char *dir,
27 const char *extension, uint flag)
29 char dev[FN_REFLEN], buff[FN_REFLEN], *pos, *startpos;
34 DBUG_ENTER(
"fn_format");
35 DBUG_ASSERT(name != NULL);
36 DBUG_ASSERT(extension != NULL);
37 DBUG_PRINT(
"enter",(
"name: %s dir: %s extension: %s flag: %d",
38 name,dir,extension,flag));
41 name+=(length=dirname_part(dev, (startpos=(
char *) name), &dev_length));
42 if (length == 0 || (flag & MY_REPLACE_DIR))
44 DBUG_ASSERT(dir != NULL);
46 convert_dirname(dev,dir,NullS);
48 else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
50 DBUG_ASSERT(dir != NULL);
52 strmake(buff,dev,
sizeof(buff)-1);
53 pos=convert_dirname(dev,dir,NullS);
54 strmake(pos,buff,
sizeof(buff)-1- (
int) (pos-dev));
57 if (flag & MY_PACK_FILENAME)
58 pack_dirname(dev,dev);
59 if (flag & MY_UNPACK_FILENAME)
60 (void) unpack_dirname(dev, dev, ¬_used);
62 if (!(flag & MY_APPEND_EXT) &&
63 (pos= (
char*) strchr(name,FN_EXTCHAR)) != NullS)
65 if ((flag & MY_REPLACE_EXT) == 0)
67 length=strlength(name);
72 length= (size_t) (pos-(
char*)
name);
78 length=strlength(name);
82 if (strlen(dev)+length+strlen(ext) >= FN_REFLEN || length >= FN_LEN )
86 if (flag & MY_SAFE_PATH)
88 tmp_length= strlength(startpos);
89 DBUG_PRINT(
"error",(
"dev: '%s' ext: '%s' length: %u",dev,ext,
91 (void) strmake(to, startpos, MY_MIN(tmp_length, FN_REFLEN-1));
97 bmove(buff,(uchar*) name,length);
100 pos=strmake(strmov(to,dev),name,length);
101 (void) strmov(pos,ext);
107 if (flag & MY_RETURN_REAL_PATH)
108 (void) my_realpath(to, to, MYF(flag & MY_RESOLVE_SYMLINKS ?
109 MY_RESOLVE_LINK: 0));
110 else if (flag & MY_RESOLVE_SYMLINKS)
113 (void) my_readlink(to, buff, MYF(0));
124 size_t strlength(
const char *str)
126 reg1
const char * pos;
127 reg2
const char * found;
128 DBUG_ENTER(
"strlength");
136 while (*++pos && *pos !=
' ') {};
144 while (*++pos ==
' ') {};
146 DBUG_RETURN((
size_t) (found - str));