13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include "drizzled/internal/my_sys.h"
19
#include "drizzled/internal/m_string.h"
16
#include "mysys/mysys_priv.h"
17
#include <mystrings/m_string.h>
20
18
#include "my_static.h"
21
#include "drizzled/error.h"
19
#include "mysys/mysys_err.h"
61
int create_temp_file(char *to, const char *dir, const char *prefix,
56
File create_temp_file(char *to, const char *dir, const char *prefix,
69
prefix_str= prefix ? prefix : "tmp.";
70
prefix_str.append("XXXXXX");
72
if (!dir && ! (dir =getenv("TMPDIR")))
74
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
76
errno=errno= ENAMETOOLONG;
79
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
81
/* TODO: This was old behavior, but really don't we want to
82
* unlink files immediately under all circumstances?
83
* if (mode & O_TEMPORARY)
84
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
86
file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags);
88
/* If we didn't manage to register the name, remove the temp file */
89
if (org_file >= 0 && file < 0)
93
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
65
if ((res=tempnam((char*) dir,(char *) prefix)))
67
strncpy(to,res,FN_REFLEN-1);
69
file=my_create(to, 0, mode | O_EXCL, MyFlags);
71
#elif defined(HAVE_MKSTEMP)
76
prefix_str= prefix ? prefix : "tmp.";
77
prefix_str.append("XXXXXX");
79
if (!dir && ! (dir =getenv("TMPDIR")))
81
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
83
errno=my_errno= ENAMETOOLONG;
86
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
88
/* TODO: This was old behavior, but really don't we want to
89
* unlink files immediately under all circumstances?
90
* if (mode & O_TEMPORARY)
91
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
93
file=my_register_filename(org_file, to, FILE_BY_MKSTEMP,
94
EE_CANTCREATEFILE, MyFlags);
95
/* If we didn't manage to register the name, remove the temp file */
96
if (org_file >= 0 && file < 0)
100
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
104
#elif defined(HAVE_TEMPNAM)
107
char *res,**old_env,*temp_env[1];
109
{ /* Change empty string to current dir */
114
old_env= (char**) environ;
116
{ /* Don't use TMPDIR if dir is given */
117
environ=(const char**) temp_env;
120
if ((res=tempnam((char*) dir, (char*) prefix)))
122
strncpy(to,res,FN_REFLEN-1);
125
(int) (O_RDWR | O_TRUNC | O_EXCL),
129
environ=(const char**) old_env;
132
#error No implementation found for create_temp_file
135
thread_safe_increment(my_tmp_file_created,&THR_LOCK_open);
100
} /* namespace internal */
101
} /* namespace drizzled */