~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_cache.c

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* Open a temporary file and cache it with io_cache. Delete it on close */
17
17
 
18
18
#include "mysys_priv.h"
19
 
#include <mystrings/m_string.h>
20
 
#include <mysys/my_static.h>
21
 
#include <mysys/mysys_err.h>
22
 
#include <mysys/iocache.h>
23
 
 
 
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
}
24
51
 
25
52
        /*
26
53
        ** Open tempfile cached by IO_CACHE
30
57
        ** If dir is not given, use TMPDIR.
31
58
        */
32
59
 
33
 
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,
34
61
                         size_t cache_size, myf cache_myflags)
35
62
{
 
63
  DBUG_ENTER("open_cached_file");
36
64
  cache->dir=    dir ? my_strdup(dir,MYF(cache_myflags & MY_WME)) : (char*) 0;
37
65
  cache->prefix= (prefix ? my_strdup(prefix,MYF(cache_myflags & MY_WME)) :
38
66
                 (char*) 0);
41
69
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
42
70
                     MYF(cache_myflags | MY_NABP)))
43
71
  {
44
 
    return(0);
 
72
    DBUG_RETURN(0);
45
73
  }
46
 
  free(cache->dir);
47
 
  free(cache->prefix);
48
 
  return(1);
 
74
  my_free(cache->dir,   MYF(MY_ALLOW_ZERO_PTR));
 
75
  my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR));
 
76
  DBUG_RETURN(1);
49
77
}
50
78
 
51
79
        /* Create the temporary file */
52
80
 
53
 
bool real_open_cached_file(IO_CACHE *cache)
 
81
my_bool real_open_cached_file(IO_CACHE *cache)
54
82
{
55
83
  char name_buff[FN_REFLEN];
56
84
  int error=1;
 
85
  DBUG_ENTER("real_open_cached_file");
57
86
  if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix,
58
 
                                    (O_RDWR | O_TRUNC),
 
87
                                    (O_RDWR | O_BINARY | O_TRUNC |
 
88
                                     O_TEMPORARY | O_SHORT_LIVED),
59
89
                                    MYF(MY_WME))) >= 0)
60
90
  {
61
91
    error=0;
62
 
    my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
 
92
    cache_remove_open_tmp(cache, name_buff);
63
93
  }
64
 
  return(error);
 
94
  DBUG_RETURN(error);
65
95
}
66
96
 
67
97
 
68
98
void close_cached_file(IO_CACHE *cache)
69
99
{
 
100
  DBUG_ENTER("close_cached_file");
70
101
  if (my_b_inited(cache))
71
102
  {
72
103
    File file=cache->file;
79
110
      if (cache->file_name)
80
111
      {
81
112
        (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
82
 
        free(cache->file_name);
 
113
        my_free(cache->file_name,MYF(0));
83
114
      }
84
115
#endif
85
116
    }
86
 
    free(cache->dir);
87
 
    free(cache->prefix);
 
117
    my_free(cache->dir,MYF(MY_ALLOW_ZERO_PTR));
 
118
    my_free(cache->prefix,MYF(MY_ALLOW_ZERO_PTR));
88
119
  }
89
 
  return;
 
120
  DBUG_VOID_RETURN;
90
121
}