12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
16
/* Open a temporary file and cache it with io_cache. Delete it on close */
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.
32
** Open tempfile cached by 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 IO_CACHE buffer gets filled
36
** If dir is not given, use TMPDIR.
39
bool st_io_cache::open_cached_file(const char *dir_arg, const char *prefix_arg,
40
size_t cache_size_arg, myf cache_myflags)
39
bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
40
size_t cache_size, myf cache_myflags)
42
dir= dir_arg ? strdup(dir_arg) : (char*) 0;
43
prefix= (prefix_arg ? strdup(prefix_arg) : (char*) 0);
45
if ((dir == NULL) || (prefix == NULL))
42
cache->dir= dir ? strdup(dir) : (char*) 0;
43
cache->prefix= (prefix ? strdup(prefix) :
45
if ((cache->dir == NULL) || (cache->prefix == NULL))
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)))
48
cache->buffer=0; /* Mark that not open */
49
if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
50
MYF(cache_myflags | MY_NABP)))
60
/* Create the temporary file */
59
/* Create the temporary file */
62
bool st_io_cache::real_open_cached_file()
61
bool real_open_cached_file(IO_CACHE *cache)
64
63
char name_buff[FN_REFLEN];
66
if ((file= create_temp_file(name_buff, dir, prefix, MYF(MY_WME))) >= 0)
65
if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix, MYF(MY_WME))) >= 0)
68
68
my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
76
void st_io_cache::close_cached_file()
74
void close_cached_file(IO_CACHE *cache)
78
if (my_b_inited(this))
76
if (my_b_inited(cache))
81
file= -1; /* Don't flush data */
82
(void) end_io_cache();
79
cache->file= -1; /* Don't flush data */
80
(void) end_io_cache(cache);
85
(void) my_close(_file, MYF(0));
83
(void) my_close(file,MYF(0));
86
84
#ifdef CANT_DELETE_OPEN_FILES
89
(void) my_delete(file_name, MYF(MY_WME | ME_NOINPUT));
87
(void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
88
free(cache->file_name);
99
98
} /* namespace internal */