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>
25
Read the contents of a .frm file.
27
frmdata and len are set to 0 on error.
29
@param name path to table-file "db/name"
30
@param frmdata frm data
31
@param len length of the read frmdata
40
3 Could not allocate data for read. Could not read file
42
int readfrm(const char *name, uchar **frmdata, size_t *len)
45
char index_file[FN_REFLEN];
51
*frmdata= NULL; // In case of errors
54
if ((file=my_open(fn_format(index_file,name,"",reg_ext,
55
MY_UNPACK_FILENAME|MY_APPEND_EXT),
62
if (fstat(file, &state))
64
read_len= state.st_size;
66
// Read whole frm file
68
read_data= 0; // Nothing to free
69
if (read_string(file, &read_data, read_len))
73
*frmdata= (uchar*) read_data;
79
VOID(my_close(file,MYF(MY_WME)));
81
err_end: /* Here when no file */
87
Write the content of a frm data pointer
90
@param name path to table-file "db/name"
91
@param frmdata frm data
92
@param len length of the frmdata
97
2 Could not write file
99
int writefrm(const char *name, const uchar *frmdata, size_t len)
102
char index_file[FN_REFLEN];
106
if ((file=my_create(fn_format(index_file,name,"",reg_ext,
107
MY_UNPACK_FILENAME|MY_APPEND_EXT),
108
CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
110
if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP)))
112
VOID(my_close(file,MYF(0)));