18 #include "mysys_priv.h"
20 #include "my_static.h"
21 #include "mysys_err.h"
29 static my_bool cache_remove_open_tmp(
IO_CACHE *cache __attribute__((unused)),
33 #if !defined(CANT_DELETE_OPEN_FILES)
35 (void) my_delete(name,MYF(MY_WME | ME_NOINPUT));
38 if (!(cache->file_name=
39 (
char*) my_malloc((length=strlen(name)+1),MYF(MY_WME))))
41 my_close(cache->file,MYF(0));
43 errno=my_errno=ENOMEM;
46 memcpy(cache->file_name,name,length);
60 my_bool open_cached_file(
IO_CACHE *cache,
const char* dir,
const char *prefix,
61 size_t cache_size, myf cache_myflags)
63 DBUG_ENTER(
"open_cached_file");
64 cache->dir= dir ? my_strdup(dir,MYF(cache_myflags & MY_WME)) : (char*) 0;
65 cache->prefix= (prefix ? my_strdup(prefix,MYF(cache_myflags & MY_WME)) :
69 if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
70 MYF(cache_myflags | MY_NABP)))
75 my_free(cache->prefix);
81 my_bool real_open_cached_file(
IO_CACHE *cache)
83 char name_buff[FN_REFLEN];
85 DBUG_ENTER(
"real_open_cached_file");
86 if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix,
87 (O_RDWR | O_BINARY | O_TRUNC |
88 O_TEMPORARY | O_SHORT_LIVED),
92 cache_remove_open_tmp(cache, name_buff);
98 void close_cached_file(
IO_CACHE *cache)
100 DBUG_ENTER(
"close_cached_file");
101 if (my_b_inited(cache))
103 File
file=cache->file;
105 (void) end_io_cache(cache);
108 (void) my_close(file,MYF(0));
109 #ifdef CANT_DELETE_OPEN_FILES
110 if (cache->file_name)
112 (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
113 my_free(cache->file_name);
118 my_free(cache->prefix);