~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_cache.c

Removed reference to aio.h - we don't reference its use anywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Open a temporary file and cache it with io_cache. Delete it on close */
17
17
 
18
 
#include "config.h"
19
 
 
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"
25
 
 
26
 
namespace drizzled
27
 
{
28
 
namespace internal
29
 
{
 
18
#include "mysys_priv.h"
 
19
#include <m_string.h>
 
20
#include "my_static.h"
 
21
#include "mysys_err.h"
 
22
 
 
23
        /*
 
24
          Remove an open tempfile so that it doesn't survive
 
25
          if we crash;  If the operating system doesn't support
 
26
          this, just remember the file name for later removal
 
27
        */
 
28
 
 
29
static my_bool cache_remove_open_tmp(IO_CACHE *cache __attribute__((unused)),
 
30
                                     const char *name)
 
31
{
 
32
#if O_TEMPORARY == 0
 
33
#if !defined(CANT_DELETE_OPEN_FILES)
 
34
  /* The following should always succeed */
 
35
  (void) my_delete(name,MYF(MY_WME | ME_NOINPUT));
 
36
#else
 
37
  int length;
 
38
  if (!(cache->file_name=
 
39
        (char*) my_malloc((length=strlen(name)+1),MYF(MY_WME))))
 
40
  {
 
41
    my_close(cache->file,MYF(0));
 
42
    cache->file = -1;
 
43
    errno=my_errno=ENOMEM;
 
44
    return 1;
 
45
  }
 
46
  memcpy(cache->file_name,name,length);
 
47
#endif
 
48
#endif /* O_TEMPORARY == 0 */
 
49
  return 0;
 
50
}
30
51
 
31
52
        /*
32
53
        ** Open tempfile cached by IO_CACHE
33
54
        ** Should be used when no seeks are done (only reinit_io_buff)
34
 
        ** Return false if cache is inited ok
 
55
        ** Return 0 if cache is inited ok
35
56
        ** The actual file is created when the IO_CACHE buffer gets filled
36
57
        ** If dir is not given, use TMPDIR.
37
58
        */
38
59
 
39
 
bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
 
60
my_bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
40
61
                         size_t cache_size, myf cache_myflags)
41
62
{
42
 
  cache->dir=    dir ? strdup(dir) : (char*) 0;
43
 
  cache->prefix= (prefix ? strdup(prefix) :
 
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)) :
44
66
                 (char*) 0);
45
 
  if ((cache->dir == NULL) || (cache->prefix == NULL))
46
 
    return true;
47
67
  cache->file_name=0;
48
68
  cache->buffer=0;                              /* Mark that not open */
49
69
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
50
70
                     MYF(cache_myflags | MY_NABP)))
51
71
  {
52
 
    return false;
 
72
    DBUG_RETURN(0);
53
73
  }
54
 
  free(cache->dir);
55
 
  free(cache->prefix);
56
 
  return true;
 
74
  my_free(cache->dir,   MYF(MY_ALLOW_ZERO_PTR));
 
75
  my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR));
 
76
  DBUG_RETURN(1);
57
77
}
58
78
 
59
79
        /* Create the temporary file */
60
80
 
61
 
bool real_open_cached_file(IO_CACHE *cache)
 
81
my_bool real_open_cached_file(IO_CACHE *cache)
62
82
{
63
83
  char name_buff[FN_REFLEN];
64
84
  int error=1;
65
 
  if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix, MYF(MY_WME))) >= 0)
 
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),
 
89
                                    MYF(MY_WME))) >= 0)
66
90
  {
67
91
    error=0;
68
 
    my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
 
92
    cache_remove_open_tmp(cache, name_buff);
69
93
  }
70
 
  return(error);
 
94
  DBUG_RETURN(error);
71
95
}
72
96
 
73
97
 
74
98
void close_cached_file(IO_CACHE *cache)
75
99
{
 
100
  DBUG_ENTER("close_cached_file");
76
101
  if (my_b_inited(cache))
77
102
  {
78
 
    int file=cache->file;
 
103
    File file=cache->file;
79
104
    cache->file= -1;                            /* Don't flush data */
80
105
    (void) end_io_cache(cache);
81
106
    if (file >= 0)
85
110
      if (cache->file_name)
86
111
      {
87
112
        (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
88
 
        free(cache->file_name);
 
113
        my_free(cache->file_name,MYF(0));
89
114
      }
90
115
#endif
91
116
    }
92
 
    free(cache->dir);
93
 
    free(cache->prefix);
 
117
    my_free(cache->dir,MYF(MY_ALLOW_ZERO_PTR));
 
118
    my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR));
94
119
  }
95
 
  return;
 
120
  DBUG_VOID_RETURN;
96
121
}
97
 
 
98
 
} /* namespace internal */
99
 
} /* namespace drizzled */