1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
16 |
#include "config.h" |
17 |
||
18 |
#include "drizzled/internal/my_sys.h" |
|
1241.9.64
by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal. |
19 |
#include "drizzled/internal/m_string.h" |
1
by brian
clean slate |
20 |
#include "my_static.h" |
1271.5.3
by Tim Penhey
change the include files |
21 |
#include "drizzled/error.h" |
612.2.6
by Monty Taylor
OpenSolaris builds. |
22 |
#include <stdio.h> |
1
by brian
clean slate |
23 |
#include <errno.h> |
670.3.1
by Toru Maesaka
Replaced MySQL's my_stpncpy() with libc and c++ calls |
24 |
#include <string> |
1
by brian
clean slate |
25 |
#ifdef HAVE_PATHS_H
|
26 |
#include <paths.h> |
|
27 |
#endif
|
|
28 |
||
670.3.3
by Toru Maesaka
Added namespacing for std to .cc files that needed it |
29 |
using namespace std; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
30 |
namespace drizzled |
31 |
{
|
|
32 |
namespace internal |
|
33 |
{
|
|
1
by brian
clean slate |
34 |
|
35 |
/*
|
|
36 |
@brief
|
|
37 |
Create a temporary file with unique name in a given directory
|
|
38 |
||
39 |
@details
|
|
40 |
create_temp_file
|
|
41 |
to pointer to buffer where temporary filename will be stored
|
|
42 |
dir directory where to create the file
|
|
43 |
prefix prefix the filename with this
|
|
44 |
MyFlags Magic flags
|
|
45 |
||
46 |
@return
|
|
47 |
File descriptor of opened file if success
|
|
48 |
-1 and sets errno if fails.
|
|
49 |
||
50 |
@note
|
|
51 |
The behaviour of this function differs a lot between
|
|
52 |
implementation, it's main use is to generate a file with
|
|
53 |
a name that does not already exist.
|
|
54 |
||
55 |
The implementation using mkstemp should be considered the
|
|
56 |
reference implementation when adding a new or modifying an
|
|
57 |
existing one
|
|
58 |
||
59 |
*/
|
|
60 |
||
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
61 |
int create_temp_file(char *to, const char *dir, const char *prefix, |
62 |
myf MyFlags) |
|
1
by brian
clean slate |
63 |
{
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
64 |
int file= -1; |
1
by brian
clean slate |
65 |
|
1241.9.1
by Monty Taylor
Removed global.h. Fixed all the headers. |
66 |
int org_file; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
67 |
string prefix_str; |
68 |
||
69 |
prefix_str= prefix ? prefix : "tmp."; |
|
70 |
prefix_str.append("XXXXXX"); |
|
71 |
||
72 |
if (!dir && ! (dir =getenv("TMPDIR"))) |
|
73 |
dir= P_tmpdir; |
|
74 |
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2) |
|
75 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
76 |
errno=errno= ENAMETOOLONG; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
77 |
return(file); |
78 |
}
|
|
79 |
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str()); |
|
80 |
org_file=mkstemp(to); |
|
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));
|
|
85 |
*/
|
|
86 |
file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags); |
|
87 |
||
88 |
/* If we didn't manage to register the name, remove the temp file */
|
|
89 |
if (org_file >= 0 && file < 0) |
|
90 |
{
|
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
91 |
int tmp=errno; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
92 |
close(org_file); |
93 |
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT)); |
|
1241.9.57
by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined. |
94 |
errno=tmp; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
95 |
}
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
96 |
|
51.3.21
by Jay Pipes
Phase 8 - Remove DBUG from mysys |
97 |
return(file); |
1
by brian
clean slate |
98 |
}
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
99 |
|
100 |
} /* namespace internal */ |
|
101 |
} /* namespace drizzled */ |