1
/* Copyright (C) 2004 MySQL AB
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.
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.
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 */
20
Functions for discover of frm file from handler
22
#include <drizzled/server_includes.h>
24
extern char reg_ext[FN_EXTLEN];
27
Read the contents of a .frm file.
29
frmdata and len are set to 0 on error.
31
@param name path to table-file "db/name"
32
@param frmdata frm data
33
@param len length of the read frmdata
42
3 Could not allocate data for read. Could not read file
44
int readfrm(const char *name, unsigned char **frmdata, size_t *len)
47
char index_file[FN_REFLEN];
50
unsigned char *read_data;
53
*frmdata= NULL; // In case of errors
56
if ((file=my_open(fn_format(index_file,name,"",reg_ext,
57
MY_UNPACK_FILENAME|MY_APPEND_EXT),
64
if (fstat(file, &state))
66
read_len= state.st_size;
68
// Read whole frm file
70
read_data= 0; // Nothing to free
71
if (read_string(file, &read_data, read_len))
75
*frmdata= (unsigned char*) read_data;
81
my_close(file,MYF(MY_WME));
83
err_end: /* Here when no file */
89
Write the content of a frm data pointer
92
@param name path to table-file "db/name"
93
@param frmdata frm data
94
@param len length of the frmdata
99
2 Could not write file
101
int writefrm(const char *name, const unsigned char *frmdata, size_t len)
104
char index_file[FN_REFLEN];
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)
112
if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP)))
114
my_close(file,MYF(0));