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

Function create_temp_file

mysys/mf_tempfile.c:57–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55*/
56
57File create_temp_file(char *to, const char *dir, const char *prefix,
58 int mode __attribute__((unused)),
59 myf MyFlags __attribute__((unused)))
60{
61 File file= -1;
62#ifdef __WIN__
63 TCHAR path_buf[MAX_PATH-14];
64#endif
65
66 DBUG_ENTER("create_temp_file");
67 DBUG_PRINT("enter", ("dir: %s, prefix: %s", dir, prefix));
68#if defined (__WIN__)
69
70 /*
71 Use GetTempPath to determine path for temporary files.
72 This is because the documentation for GetTempFileName
73 has the following to say about this parameter:
74 "If this parameter is NULL, the function fails."
75 */
76 if (!dir)
77 {
78 if(GetTempPath(sizeof(path_buf), path_buf) > 0)
79 dir = path_buf;
80 }
81 /*
82 Use GetTempFileName to generate a unique filename, create
83 the file and release it's handle
84 - uses up to the first three letters from prefix
85 */
86 if (GetTempFileName(dir, prefix, 0, to) == 0)
87 DBUG_RETURN(-1);
88
89 DBUG_PRINT("info", ("name: %s", to));
90
91 /*
92 Open the file without the "open only if file doesn't already exist"
93 since the file has already been created by GetTempFileName
94 */
95 if ((file= my_open(to, (mode & ~O_EXCL), MyFlags)) < 0)
96 {
97 /* Open failed, remove the file created by GetTempFileName */
98 int tmp= my_errno;
99 (void) my_delete(to, MYF(0));
100 my_errno= tmp;
101 }
102
103#elif defined(HAVE_MKSTEMP)
104 {
105 char prefix_buff[30];
106 uint pfx_len;
107 File org_file;
108
109 pfx_len= (uint) (strmov(strnmov(prefix_buff,
110 prefix ? prefix : "tmp.",
111 sizeof(prefix_buff)-7),"XXXXXX") -
112 prefix_buff);
113 if (!dir && ! (dir =getenv("TMPDIR")))
114 dir= DEFAULT_TMPDIR;

Callers 3

real_open_cached_fileFunction · 0.85
convert_fileFunction · 0.85

Calls 8

my_openFunction · 0.85
my_deleteFunction · 0.85
strmovFunction · 0.85
strnmovFunction · 0.85
convert_dirnameFunction · 0.85
my_register_filenameFunction · 0.85
strmakeFunction · 0.85
my_createFunction · 0.85

Tested by

no test coverage detected