~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2004 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
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/**
17
  @file
18
19
  @brief
20
  Functions for discover of frm file from handler
21
*/
243.1.17 by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.)
22
#include <drizzled/server_includes.h>
1 by brian
clean slate
23
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
24
extern char reg_ext[FN_EXTLEN];
25
1 by brian
clean slate
26
/**
27
  Read the contents of a .frm file.
28
29
  frmdata and len are set to 0 on error.
30
31
  @param name           path to table-file "db/name"
32
  @param frmdata        frm data
33
  @param len            length of the read frmdata
34
35
  @retval
36
    0	ok
37
  @retval
38
    1	Could not open file
39
  @retval
40
    2    Could not stat file
41
  @retval
42
    3    Could not allocate data for read.  Could not read file
43
*/
481 by Brian Aker
Remove all of uchar.
44
int readfrm(const char *name, unsigned char **frmdata, size_t *len)
1 by brian
clean slate
45
{
46
  int    error;
47
  char	 index_file[FN_REFLEN];
48
  File	 file;
49
  size_t read_len;
481 by Brian Aker
Remove all of uchar.
50
  unsigned char *read_data;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
51
  struct stat state;
52
1 by brian
clean slate
53
  *frmdata= NULL;      // In case of errors
54
  *len= 0;
55
  error= 1;
56
  if ((file=my_open(fn_format(index_file,name,"",reg_ext,
57
                              MY_UNPACK_FILENAME|MY_APPEND_EXT),
492.1.13 by Monty Taylor
Removed O_SHARE. I think it was only for OS/2.
58
		    O_RDONLY,
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
59
		    MYF(0))) < 0)
60
    goto err_end;
61
1 by brian
clean slate
62
  // Get length of file
63
  error= 2;
15 by brian
Fix for stat, NETWARE removal
64
  if (fstat(file, &state))
1 by brian
clean slate
65
    goto err;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
66
  read_len= state.st_size;
1 by brian
clean slate
67
68
  // Read whole frm file
69
  error= 3;
70
  read_data= 0;                                 // Nothing to free
71
  if (read_string(file, &read_data, read_len))
72
    goto err;
73
74
  // Setup return data
481 by Brian Aker
Remove all of uchar.
75
  *frmdata= (unsigned char*) read_data;
1 by brian
clean slate
76
  *len= read_len;
77
  error= 0;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
78
1 by brian
clean slate
79
 err:
80
  if (file > 0)
398.1.10 by Monty Taylor
Actually removed VOID() this time.
81
    my_close(file,MYF(MY_WME));
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
82
1 by brian
clean slate
83
 err_end:		      /* Here when no file */
51.1.79 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols, and removed custom dbug funcs for decimal (these should go away anyway...)
84
  return(error);
1 by brian
clean slate
85
} /* readfrm */
86
87
88
/*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
89
  Write the content of a frm data pointer
1 by brian
clean slate
90
  to a frm file.
91
92
  @param name           path to table-file "db/name"
93
  @param frmdata        frm data
94
  @param len            length of the frmdata
95
96
  @retval
97
    0	ok
98
  @retval
99
    2    Could not write file
100
*/
481 by Brian Aker
Remove all of uchar.
101
int writefrm(const char *name, const unsigned char *frmdata, size_t len)
1 by brian
clean slate
102
{
103
  File file;
104
  char	 index_file[FN_REFLEN];
105
  int error;
106
107
  error= 0;
108
  if ((file=my_create(fn_format(index_file,name,"",reg_ext,
109
                      MY_UNPACK_FILENAME|MY_APPEND_EXT),
110
		      CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
111
  {
112
    if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP)))
113
      error= 2;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
114
    my_close(file,MYF(0));
1 by brian
clean slate
115
  }
51.1.78 by Jay Pipes
Standardized TRUE/FALSE, removed/replaced DBUG symbols
116
  return(error);
1 by brian
clean slate
117
} /* writefrm */