~drizzle-trunk/drizzle/development

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