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