1
by brian
clean slate |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
994.2.4
by Monty Taylor
Blast. Fixed some make distcheck issues. |
16 |
#include "mysys/mysys_priv.h" |
685.1.3
by Monty Taylor
Turned off stdinc - and then fixed the carnage. |
17 |
#include "my_dir.h" |
994.2.4
by Monty Taylor
Blast. Fixed some make distcheck issues. |
18 |
#include "mysys/mysys_err.h" |
685.1.3
by Monty Taylor
Turned off stdinc - and then fixed the carnage. |
19 |
|
1
by brian
clean slate |
20 |
#include <errno.h> |
21 |
/*
|
|
22 |
** Create a new file
|
|
23 |
** Arguments:
|
|
24 |
** Path-name of file
|
|
25 |
** Read | write on file (umask value)
|
|
26 |
** Read & Write on open file
|
|
27 |
** Special flags
|
|
28 |
*/
|
|
29 |
||
30 |
||
31 |
File my_create(const char *FileName, int CreateFlags, int access_flags, |
|
685.3.1
by Toru Maesaka
Removed my_mkdir() and my_sleep() |
32 |
myf MyFlags) |
1
by brian
clean slate |
33 |
{
|
34 |
int fd, rc; |
|
35 |
||
36 |
#if !defined(NO_OPEN_3)
|
|
266.7.14
by Andy Lester
Removed unnecessary cast |
37 |
fd = open(FileName, access_flags | O_CREAT, |
1
by brian
clean slate |
38 |
CreateFlags ? CreateFlags : my_umask); |
39 |
#else
|
|
40 |
fd = open(FileName, access_flags); |
|
41 |
#endif
|
|
42 |
||
43 |
if ((MyFlags & MY_SYNC_DIR) && (fd >=0) && |
|
44 |
my_sync_dir_by_file(FileName, MyFlags)) |
|
45 |
{
|
|
46 |
my_close(fd, MyFlags); |
|
47 |
fd= -1; |
|
48 |
}
|
|
49 |
||
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
50 |
rc= my_register_filename(fd, FileName, EE_CANTCREATEFILE, MyFlags); |
1
by brian
clean slate |
51 |
/*
|
52 |
my_register_filename() may fail on some platforms even if the call to
|
|
53 |
*open() above succeeds. In this case, don't leave the stale file because
|
|
54 |
callers assume the file to not exist if my_create() fails, so they don't
|
|
55 |
do any cleanups.
|
|
56 |
*/
|
|
57 |
if (unlikely(fd >= 0 && rc < 0)) |
|
58 |
{
|
|
59 |
int tmp= my_errno; |
|
60 |
my_delete(FileName, MyFlags); |
|
61 |
my_errno= tmp; |
|
62 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
63 |
|
51.3.20
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
64 |
return(rc); |
1
by brian
clean slate |
65 |
} /* my_create */ |