mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / myisammrg / myrg_create.c
blob2720aeae894fcdf2f4d1867116c51c1ac9dde45c
1 /*
2 Copyright (c) 2000, 2001, 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc.
3 Use is subject to license terms.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 /* Create a MYMERGE_-file */
21 #include "myrg_def.h"
23 /* create file named 'name' and save filenames in it
24 table_names should be NULL or a vector of string-pointers with
25 a NULL-pointer last
28 int myrg_create(const char *name, const char **table_names,
29 uint insert_method, my_bool fix_names)
31 int save_errno;
32 uint errpos;
33 File file;
34 char buff[FN_REFLEN],*end;
35 DBUG_ENTER("myrg_create");
37 errpos=0;
38 if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT,
39 MY_UNPACK_FILENAME|MY_APPEND_EXT),0,
40 O_RDWR | O_EXCL | O_NOFOLLOW,MYF(MY_WME))) < 0)
41 goto err;
42 errpos=1;
43 if (table_names)
45 for ( ; *table_names ; table_names++)
47 strmov(buff,*table_names);
48 if (fix_names)
49 fn_same(buff,name,4);
50 *(end=strend(buff))='\n';
51 end[1]=0;
52 if (my_write(file,(uchar*) buff,(uint) (end-buff+1),
53 MYF(MY_WME | MY_NABP)))
54 goto err;
57 if (insert_method != MERGE_INSERT_DISABLED)
59 end=strxmov(buff,"#INSERT_METHOD=",
60 get_type(&merge_insert_method,insert_method-1),"\n",NullS);
61 if (my_write(file, (uchar*) buff,(uint) (end-buff),MYF(MY_WME | MY_NABP)))
62 goto err;
64 if (my_close(file,MYF(0)))
65 goto err;
66 DBUG_RETURN(0);
68 err:
69 save_errno=my_errno ? my_errno : -1;
70 switch (errpos) {
71 case 1:
72 VOID(my_close(file,MYF(0)));
74 DBUG_RETURN(my_errno=save_errno);
75 } /* myrg_create */