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 |
|
16 |
/* Open a temporary file and cache it with io_cache. Delete it on close */
|
|
17 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
18 |
#include <config.h> |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
19 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <drizzled/internal/my_sys.h> |
21 |
#include <drizzled/internal/m_string.h> |
|
22 |
#include <drizzled/internal/my_static.h> |
|
23 |
#include <drizzled/internal/iocache.h> |
|
24 |
#include <drizzled/error.h> |
|
1
by brian
clean slate |
25 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
26 |
namespace drizzled |
27 |
{
|
|
28 |
namespace internal |
|
29 |
{
|
|
1
by brian
clean slate |
30 |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
31 |
/*
|
32 |
** Open tempfile cached by st_io_cache
|
|
33 |
** Should be used when no seeks are done (only reinit_io_buff)
|
|
34 |
** Return false if cache is inited ok
|
|
35 |
** The actual file is created when the st_io_cache buffer gets filled
|
|
36 |
** If dir is not given, use TMPDIR.
|
|
37 |
*/
|
|
1
by brian
clean slate |
38 |
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
39 |
bool st_io_cache::open_cached_file(const char *dir_arg, const char *prefix_arg, |
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
40 |
size_t cache_size_arg, myf cache_myflags) |
1
by brian
clean slate |
41 |
{
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
42 |
dir= dir_arg ? strdup(dir_arg) : (char*) 0; |
43 |
prefix= (prefix_arg ? strdup(prefix_arg) : (char*) 0); |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
44 |
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
45 |
if ((dir == NULL) || (prefix == NULL)) |
656.1.52
by Monty Taylor
Added more return value checks. |
46 |
return true; |
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
47 |
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
48 |
file_name= 0; |
49 |
buffer= 0; /* Mark that not open */ |
|
50 |
if (not init_io_cache(-1, cache_size_arg,WRITE_CACHE,0L,0, MYF(cache_myflags | MY_NABP))) |
|
1
by brian
clean slate |
51 |
{
|
656.1.52
by Monty Taylor
Added more return value checks. |
52 |
return false; |
1
by brian
clean slate |
53 |
}
|
1909.1.2
by Brian Aker
Additional io_cache encapsulation. |
54 |
free(dir); |
55 |
free(prefix); |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
56 |
|
656.1.52
by Monty Taylor
Added more return value checks. |
57 |
return true; |
1
by brian
clean slate |
58 |
}
|
59 |
||
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
60 |
/* Create the temporary file */
|
1
by brian
clean slate |
61 |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
62 |
bool st_io_cache::real_open_cached_file() |
1
by brian
clean slate |
63 |
{
|
64 |
char name_buff[FN_REFLEN]; |
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
65 |
|
66 |
if ((file= create_temp_file(name_buff, dir, prefix, MYF(MY_WME))) >= 0) |
|
1
by brian
clean slate |
67 |
{
|
499.1.4
by Monty Taylor
Fixed two things I missed. |
68 |
my_delete(name_buff,MYF(MY_WME | ME_NOINPUT)); |
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
69 |
return false; |
1
by brian
clean slate |
70 |
}
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
71 |
|
72 |
return true; |
|
1
by brian
clean slate |
73 |
}
|
74 |
||
75 |
||
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
76 |
void st_io_cache::close_cached_file() |
1
by brian
clean slate |
77 |
{
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
78 |
if (my_b_inited(this)) |
1
by brian
clean slate |
79 |
{
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
80 |
int _file= file; |
81 |
file= -1; /* Don't flush data */ |
|
82 |
(void) end_io_cache(); |
|
83 |
if (_file >= 0) |
|
1
by brian
clean slate |
84 |
{
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
85 |
(void) my_close(_file, MYF(0)); |
1
by brian
clean slate |
86 |
#ifdef CANT_DELETE_OPEN_FILES
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
87 |
if (file_name) |
1
by brian
clean slate |
88 |
{
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
89 |
(void) my_delete(file_name, MYF(MY_WME | ME_NOINPUT)); |
90 |
free(file_name); |
|
1
by brian
clean slate |
91 |
}
|
92 |
#endif
|
|
93 |
}
|
|
1909.1.1
by Brian Aker
Encapsulation of IO_CACHE. |
94 |
free(dir); |
95 |
free(prefix); |
|
1
by brian
clean slate |
96 |
}
|
97 |
}
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
98 |
|
99 |
} /* namespace internal */ |
|
100 |
} /* namespace drizzled */ |