Drizzled Public API Documentation

my_create.cc
1 /* Copyright (C) 2000 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include <config.h>
17 
18 #include <drizzled/internal/my_sys.h>
19 
20 #include <fcntl.h>
21 #include <errno.h>
22 
23 #include <drizzled/error.h>
24 
25  /*
26  ** Create a new file
27  ** Arguments:
28  ** Path-name of file
29  ** Read | write on file (umask value)
30  ** Read & Write on open file
31  ** Special flags
32  */
33 
34 namespace drizzled
35 {
36 namespace internal
37 {
38 
39 int my_create(const char *FileName, int CreateFlags, int access_flags,
40  myf MyFlags)
41 {
42  int fd, rc;
43 
44 #if !defined(NO_OPEN_3)
45  fd = open(FileName, access_flags | O_CREAT,
46  CreateFlags ? CreateFlags : my_umask);
47 #else
48  fd = open(FileName, access_flags);
49 #endif
50 
51  if ((MyFlags & MY_SYNC_DIR) && (fd >=0) &&
52  my_sync_dir_by_file(FileName, MyFlags))
53  {
54  my_close(fd, MyFlags);
55  fd= -1;
56  }
57 
58  rc= my_register_filename(fd, FileName, EE_CANTCREATEFILE, MyFlags);
59  /*
60  my_register_filename() may fail on some platforms even if the call to
61  *open() above succeeds. In this case, don't leave the stale file because
62  callers assume the file to not exist if my_create() fails, so they don't
63  do any cleanups.
64  */
65  if (unlikely(fd >= 0 && rc < 0))
66  {
67  int tmp= errno;
68  my_delete(FileName, MyFlags);
69  errno= tmp;
70  }
71 
72  return(rc);
73 } /* my_create */
74 
75 } /* namespace internal */
76 } /* namespace drizzled */