16 #include "mysys_priv.h"
18 #include "my_static.h"
19 #include "mysys_err.h"
57 File create_temp_file(
char *
to,
const char *dir,
const char *prefix,
58 int mode __attribute__((unused)),
59 myf MyFlags __attribute__((unused)))
63 TCHAR path_buf[MAX_PATH-14];
66 DBUG_ENTER(
"create_temp_file");
67 DBUG_PRINT(
"enter", (
"dir: %s, prefix: %s", dir, prefix));
78 if(GetTempPath(
sizeof(path_buf), path_buf) > 0)
86 if (GetTempFileName(dir, prefix, 0, to) == 0)
89 DBUG_PRINT(
"info", (
"name: %s", to));
95 if ((file= my_open(to, (
mode & ~O_EXCL), MyFlags)) < 0)
99 (void) my_delete(to, MYF(0));
103 #elif defined(HAVE_MKSTEMP)
105 char prefix_buff[30];
109 pfx_len= (uint) (strmov(strnmov(prefix_buff,
110 prefix ? prefix :
"tmp.",
111 sizeof(prefix_buff)-7),
"XXXXXX") -
113 if (!dir && ! (dir =getenv(
"TMPDIR")))
115 if (strlen(dir)+ pfx_len > FN_REFLEN-2)
117 errno=my_errno= ENAMETOOLONG;
120 strmov(convert_dirname(to,dir,NullS),prefix_buff);
121 org_file=mkstemp(to);
122 if (
mode & O_TEMPORARY)
123 (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
124 file=my_register_filename(org_file, to, FILE_BY_MKSTEMP,
125 EE_CANTCREATEFILE, MyFlags);
127 if (org_file >= 0 && file < 0)
131 (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
135 #elif defined(HAVE_TEMPNAM)
137 extern char **environ;
139 char *res,**old_env,*temp_env[1];
147 old_env= (
char**) environ;
150 environ=(
const char**) temp_env;
154 if ((res=tempnam((
char*) dir, (
char*) prefix)))
156 strmake(to,res,FN_REFLEN-1);
159 (
int) (O_RDWR | O_BINARY | O_TRUNC | O_EXCL | O_NOFOLLOW |
160 O_TEMPORARY | O_SHORT_LIVED),
166 DBUG_PRINT(
"error",(
"Got error: %d from tempnam",errno));
169 environ=(
const char**) old_env;
172 #error No implementation found for create_temp_file
175 thread_safe_increment(my_tmp_file_created,&THR_LOCK_open);