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 */
21
Functions for discover of frm file from handler
24
#include "mysql_priv.h"
28
Read the contents of a .frm file.
30
frmdata and len are set to 0 on error.
32
@param name path to table-file "db/name"
33
@param frmdata frm data
34
@param len length of the read frmdata
43
3 Could not allocate data for read. Could not read file
46
int readfrm(const char *name, uchar **frmdata, size_t *len)
49
char index_file[FN_REFLEN];
55
*frmdata= NULL; // In case of errors
58
if ((file=my_open(fn_format(index_file,name,"",reg_ext,
59
MY_UNPACK_FILENAME|MY_APPEND_EXT),
66
if (fstat(file, &state))
68
read_len= state.st_size;
70
// Read whole frm file
72
read_data= 0; // Nothing to free
73
if (read_string(file, &read_data, read_len))
77
*frmdata= (uchar*) read_data;
83
VOID(my_close(file,MYF(MY_WME)));
85
err_end: /* Here when no file */
91
Write the content of a frm data pointer
94
@param name path to table-file "db/name"
95
@param frmdata frm data
96
@param len length of the frmdata
101
2 Could not write file
104
int writefrm(const char *name, const uchar *frmdata, size_t len)
107
char index_file[FN_REFLEN];
111
if ((file=my_create(fn_format(index_file,name,"",reg_ext,
112
MY_UNPACK_FILENAME|MY_APPEND_EXT),
113
CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
115
if (my_write(file, frmdata, len,MYF(MY_WME | MY_NABP)))
117
VOID(my_close(file,MYF(0)));