55
File create_temp_file(char *to, const char *dir, const char *prefix, myf MyFlags)
55
File create_temp_file(char *to, const char *dir, const char *prefix,
62
if ((res=tempnam((char*) dir,(char *) prefix)))
64
strncpy(to,res,FN_REFLEN-1);
66
file=my_create(to, 0, mode | O_EXCL, MyFlags);
68
#elif defined(HAVE_MKSTEMP)
73
prefix_str= prefix ? prefix : "tmp.";
74
prefix_str.append("XXXXXX");
76
if (!dir && ! (dir =getenv("TMPDIR")))
78
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
80
errno=my_errno= ENAMETOOLONG;
83
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
85
/* TODO: This was old behavior, but really don't we want to
86
* unlink files immediately under all circumstances?
87
* if (mode & O_TEMPORARY)
88
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
90
file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags);
92
/* If we didn't manage to register the name, remove the temp file */
93
if (org_file >= 0 && file < 0)
97
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
101
#elif defined(HAVE_TEMPNAM)
104
char *res,**old_env,*temp_env[1];
106
{ /* Change empty string to current dir */
111
old_env= (char**) environ;
113
{ /* Don't use TMPDIR if dir is given */
114
environ=(const char**) temp_env;
117
if ((res=tempnam((char*) dir, (char*) prefix)))
119
strncpy(to,res,FN_REFLEN-1);
122
(int) (O_RDWR | O_TRUNC | O_EXCL),
126
environ=(const char**) old_env;
129
#error No implementation found for create_temp_file
63
prefix_str= prefix ? prefix : "tmp.";
64
prefix_str.append("XXXXXX");
66
if (!dir && ! (dir =getenv("TMPDIR")))
68
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
70
errno=my_errno= ENAMETOOLONG;
73
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
75
/* TODO: This was old behavior, but really don't we want to
76
* unlink files immediately under all circumstances?
77
* if (mode & O_TEMPORARY)
78
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
80
file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags);
82
/* If we didn't manage to register the name, remove the temp file */
83
if (org_file >= 0 && file < 0)
87
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
132
91
my_tmp_file_created++;