~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/myisammrg/myrg_create.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2001, 2005 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
/* Create a MYMERGE_-file */
 
17
 
 
18
#include "myrg_def.h"
 
19
 
 
20
        /* create file named 'name' and save filenames in it
 
21
           table_names should be NULL or a vector of string-pointers with
 
22
           a NULL-pointer last
 
23
           */
 
24
 
 
25
int myrg_create(const char *name, const char **table_names,
 
26
                uint insert_method, my_bool fix_names)
 
27
{
 
28
  int save_errno;
 
29
  uint errpos;
 
30
  File file;
 
31
  char buff[FN_REFLEN],*end;
 
32
  DBUG_ENTER("myrg_create");
 
33
 
 
34
  errpos=0;
 
35
  if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT,
 
36
                                  MY_UNPACK_FILENAME|MY_APPEND_EXT),0,
 
37
       O_RDWR | O_EXCL | O_NOFOLLOW,MYF(MY_WME))) < 0)
 
38
    goto err;
 
39
  errpos=1;
 
40
  if (table_names)
 
41
  {
 
42
    for ( ; *table_names ; table_names++)
 
43
    {
 
44
      strmov(buff,*table_names);
 
45
      if (fix_names)
 
46
        fn_same(buff,name,4);
 
47
      *(end=strend(buff))='\n';
 
48
      end[1]=0;
 
49
      if (my_write(file,(uchar*) buff,(uint) (end-buff+1),
 
50
                   MYF(MY_WME | MY_NABP)))
 
51
        goto err;
 
52
    }
 
53
  }
 
54
  if (insert_method != MERGE_INSERT_DISABLED)
 
55
  {
 
56
    end=strxmov(buff,"#INSERT_METHOD=",
 
57
                get_type(&merge_insert_method,insert_method-1),"\n",NullS);
 
58
    if (my_write(file, (uchar*) buff,(uint) (end-buff),MYF(MY_WME | MY_NABP)))
 
59
        goto err;
 
60
  }
 
61
  if (my_close(file,MYF(0)))
 
62
    goto err;
 
63
  DBUG_RETURN(0);
 
64
 
 
65
err:
 
66
  save_errno=my_errno ? my_errno : -1;
 
67
  switch (errpos) {
 
68
  case 1:
 
69
    VOID(my_close(file,MYF(0)));
 
70
  }
 
71
  DBUG_RETURN(my_errno=save_errno);
 
72
} /* myrg_create */