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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
16 |
#include <config.h> |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
17 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
18 |
#include <drizzled/internal/my_sys.h> |
19 |
#include <drizzled/internal/m_string.h> |
|
1
by brian
clean slate |
20 |
#include "my_static.h" |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
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 |
{
|
2241.2.9
by Olaf van der Spek
Refactor |
64 |
string prefix_str= prefix ? prefix : "tmp."; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
65 |
prefix_str.append("XXXXXX"); |
66 |
||
67 |
if (!dir && ! (dir =getenv("TMPDIR"))) |
|
68 |
dir= P_tmpdir; |
|
69 |
if (strlen(dir)+prefix_str.length() > FN_REFLEN-2) |
|
70 |
{
|
|
1831.1.1
by Andrew Hutchings
Fix new warnings in GCC 4.5 |
71 |
errno= ENAMETOOLONG; |
2241.2.9
by Olaf van der Spek
Refactor |
72 |
return -1; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
73 |
}
|
74 |
strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str()); |
|
2241.2.9
by Olaf van der Spek
Refactor |
75 |
int org_file= mkstemp(to); |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
76 |
/* TODO: This was old behavior, but really don't we want to
|
77 |
* unlink files immediately under all circumstances?
|
|
78 |
* if (mode & O_TEMPORARY)
|
|
79 |
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
|
|
80 |
*/
|
|
2241.2.9
by Olaf van der Spek
Refactor |
81 |
int file= my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags); |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
82 |
|
83 |
/* If we didn't manage to register the name, remove the temp file */
|
|
84 |
if (org_file >= 0 && file < 0) |
|
85 |
{
|
|
2241.2.9
by Olaf van der Spek
Refactor |
86 |
int tmp= errno; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
87 |
close(org_file); |
88 |
(void) my_delete(to, MYF(MY_WME | ME_NOINPUT)); |
|
2241.2.9
by Olaf van der Spek
Refactor |
89 |
errno= tmp; |
1192.3.43
by Monty Taylor
Removed many, many checks for functions that do not need to be checked. |
90 |
}
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
91 |
|
2241.2.9
by Olaf van der Spek
Refactor |
92 |
return file; |
1
by brian
clean slate |
93 |
}
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
94 |
|
95 |
} /* namespace internal */ |
|
96 |
} /* namespace drizzled */ |