~drizzle-trunk/drizzle/development

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
16
#include "mysys_priv.h"
685.1.3 by Monty Taylor
Turned off stdinc - and then fixed the carnage.
17
#include "my_dir.h"
1 by brian
clean slate
18
#include "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
50
  rc= my_register_filename(fd, FileName, FILE_BY_CREATE,
51
                           EE_CANTCREATEFILE, MyFlags);
52
  /*
53
    my_register_filename() may fail on some platforms even if the call to
54
    *open() above succeeds. In this case, don't leave the stale file because
55
    callers assume the file to not exist if my_create() fails, so they don't
56
    do any cleanups.
57
  */
58
  if (unlikely(fd >= 0 && rc < 0))
59
  {
60
    int tmp= my_errno;
61
    my_delete(FileName, MyFlags);
62
    my_errno= tmp;
63
  }
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
64
51.3.20 by Jay Pipes
Phase 6 - Remove DBUG from mysys
65
  return(rc);
1 by brian
clean slate
66
} /* my_create */