1 | /* Copyright (c) 2000, 2001, 2005-2008 MySQL AB, 2009 Sun Microsystems, Inc. |
2 | Use is subject to license terms. |
3 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; version 2 of the License. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
16 | |
17 | #include "mysys_priv.h" |
18 | #include <my_dir.h> |
19 | #include "mysys_err.h" |
20 | #include <errno.h> |
21 | #include <my_sys.h> |
22 | #if defined(_WIN32) |
23 | #include <share.h> |
24 | #endif |
25 | |
26 | /* |
27 | ** Create a new file |
28 | ** Arguments: |
29 | ** Path-name of file |
30 | ** Read | write on file (umask value) |
31 | ** Read & Write on open file |
32 | ** Special flags |
33 | */ |
34 | |
35 | |
36 | File my_create(const char *FileName, int CreateFlags, int access_flags, |
37 | myf MyFlags) |
38 | { |
39 | int fd; |
40 | DBUG_ENTER("my_create" ); |
41 | DBUG_PRINT("my" ,("Name: '%s' CreateFlags: %d AccessFlags: %d MyFlags: %lu" , |
42 | FileName, CreateFlags, access_flags, MyFlags)); |
43 | #if defined(_WIN32) |
44 | fd= my_win_open(FileName, access_flags | O_CREAT); |
45 | #else |
46 | fd= open((char *) FileName, access_flags | O_CREAT | O_CLOEXEC, |
47 | CreateFlags ? CreateFlags : my_umask); |
48 | #endif |
49 | |
50 | if ((MyFlags & MY_SYNC_DIR) && (fd >=0) && |
51 | my_sync_dir_by_file(FileName, MyFlags)) |
52 | { |
53 | my_close(fd, MyFlags); |
54 | fd= -1; |
55 | } |
56 | |
57 | fd= my_register_filename(fd, FileName, FILE_BY_CREATE, |
58 | EE_CANTCREATEFILE, MyFlags); |
59 | DBUG_RETURN(fd); |
60 | } /* my_create */ |
61 | |