Drizzled Public API Documentation

my_create.cc
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #include <config.h>
00017 
00018 #include <drizzled/internal/my_sys.h>
00019 
00020 #include <fcntl.h>
00021 #include <errno.h>
00022 
00023 #include <drizzled/error.h>
00024 
00025   /*
00026   ** Create a new file
00027   ** Arguments:
00028   ** Path-name of file
00029   ** Read | write on file (umask value)
00030   ** Read & Write on open file
00031   ** Special flags
00032   */
00033 
00034 namespace drizzled
00035 {
00036 namespace internal
00037 {
00038 
00039 int my_create(const char *FileName, int CreateFlags, int access_flags,
00040               myf MyFlags)
00041 {
00042   int fd, rc;
00043 
00044 #if !defined(NO_OPEN_3)
00045   fd = open(FileName, access_flags | O_CREAT,
00046       CreateFlags ? CreateFlags : my_umask);
00047 #else
00048   fd = open(FileName, access_flags);
00049 #endif
00050 
00051   if ((MyFlags & MY_SYNC_DIR) && (fd >=0) &&
00052       my_sync_dir_by_file(FileName, MyFlags))
00053   {
00054     my_close(fd, MyFlags);
00055     fd= -1;
00056   }
00057 
00058   rc= my_register_filename(fd, FileName, EE_CANTCREATEFILE, MyFlags);
00059   /*
00060     my_register_filename() may fail on some platforms even if the call to
00061     *open() above succeeds. In this case, don't leave the stale file because
00062     callers assume the file to not exist if my_create() fails, so they don't
00063     do any cleanups.
00064   */
00065   if (unlikely(fd >= 0 && rc < 0))
00066   {
00067     int tmp= errno;
00068     my_delete(FileName, MyFlags);
00069     errno= tmp;
00070   }
00071 
00072   return(rc);
00073 } /* my_create */
00074 
00075 } /* namespace internal */
00076 } /* namespace drizzled */