MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / fn_format

Function fn_format

mysys/mf_format.c:26–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24*/
25
26char * fn_format(char * to, const char *name, const char *dir,
27 const char *extension, uint flag)
28{
29 char dev[FN_REFLEN], buff[FN_REFLEN], *pos, *startpos;
30 const char *ext;
31 reg1 size_t length;
32 size_t dev_length;
33 my_bool not_used;
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));
39
40 /* Copy and skip directory */
41 name+=(length=dirname_part(dev, (startpos=(char *) name), &dev_length));
42 if (length == 0 || (flag & MY_REPLACE_DIR))
43 {
44 DBUG_ASSERT(dir != NULL);
45 /* Use given directory */
46 convert_dirname(dev,dir,NullS); /* Fix to this OS */
47 }
48 else if ((flag & MY_RELATIVE_PATH) && !test_if_hard_path(dev))
49 {
50 DBUG_ASSERT(dir != NULL);
51 /* Put 'dir' before the given path */
52 strmake(buff,dev,sizeof(buff)-1);
53 pos=convert_dirname(dev,dir,NullS);
54 strmake(pos,buff,sizeof(buff)-1- (int) (pos-dev));
55 }
56
57 if (flag & MY_PACK_FILENAME)
58 pack_dirname(dev,dev); /* Put in ./.. and ~/.. */
59 if (flag & MY_UNPACK_FILENAME)
60 (void) unpack_dirname(dev, dev, &not_used); /* Replace ~/.. with dir */
61
62 if (!(flag & MY_APPEND_EXT) &&
63 (pos= (char*) strchr(name,FN_EXTCHAR)) != NullS)
64 {
65 if ((flag & MY_REPLACE_EXT) == 0) /* If we should keep old ext */
66 {
67 length=strlength(name); /* Use old extension */
68 ext = "";
69 }
70 else
71 {
72 length= (size_t) (pos-(char*) name); /* Change extension */
73 ext= extension;
74 }
75 }
76 else
77 {
78 length=strlength(name); /* No ext, use the now one */
79 ext=extension;
80 }
81
82 if (strlen(dev)+length+strlen(ext) >= FN_REFLEN || length >= FN_LEN )
83 {

Callers 11

val_strMethod · 0.85
test_if_case_insensitiveFunction · 0.85
make_log_nameFunction · 0.85
generate_new_nameMethod · 0.85
generate_nameMethod · 0.85
read_textsFunction · 0.85
fn_sameFunction · 0.85
my_redelFunction · 0.85
fn_expandFunction · 0.85

Calls 10

dirname_partFunction · 0.85
convert_dirnameFunction · 0.85
test_if_hard_pathFunction · 0.85
strmakeFunction · 0.85
pack_dirnameFunction · 0.85
unpack_dirnameFunction · 0.85
strlengthFunction · 0.85
strmovFunction · 0.85
my_realpathFunction · 0.85
my_readlinkFunction · 0.85

Tested by 1

test_if_case_insensitiveFunction · 0.68