Drizzled Public API Documentation

my_open.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 #include <drizzled/error.h>
00020 
00021 #include <fcntl.h>
00022 
00023 #include <cerrno>
00024 #include <cstdlib>
00025 #include <cstring>
00026 
00027 
00028 namespace drizzled {
00029 namespace internal {
00030 
00031 /*
00032   Open a file
00033 
00034   SYNOPSIS
00035     my_open()
00036       FileName  Fully qualified file name
00037       Flags Read | write
00038       MyFlags Special flags
00039 
00040   RETURN VALUE
00041     int descriptor
00042 */
00043 
00044 int my_open(const char *FileName, int Flags, myf MyFlags)
00045         /* Path-name of file */
00046         /* Read | write .. */
00047         /* Special flags */
00048 {
00049   int fd;
00050 
00051 #if !defined(NO_OPEN_3)
00052   fd = open(FileName, Flags, my_umask); /* Normal unix */
00053 #else
00054   fd = open((char *) FileName, Flags);
00055 #endif
00056 
00057   return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags));
00058 } /* my_open */
00059 
00060 
00061 /*
00062   Close a file
00063 
00064   SYNOPSIS
00065     my_close()
00066       fd  File sescriptor
00067       myf Special Flags
00068 
00069 */
00070 
00071 int my_close(int fd, myf MyFlags)
00072 {
00073   int err;
00074 
00075   do
00076   {
00077     err= close(fd);
00078   } while (err == -1 && errno == EINTR);
00079 
00080   if (err)
00081   {
00082     errno=errno;
00083     if (MyFlags & (MY_FAE | MY_WME))
00084       my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
00085   }
00086 
00087   return(err);
00088 } /* my_close */
00089 
00090 
00091 /*
00092   TODO: Get rid of
00093 
00094   SYNOPSIS
00095     my_register_filename()
00096     fd         File number opened, -1 if error on open
00097     FileName       File name
00098     type_file_type     How file was created
00099     error_message_number   Error message number if caller got error (fd == -1)
00100     MyFlags      Flags for my_close()
00101 
00102   RETURN
00103     -1   error
00104      #   Filenumber
00105 
00106 */
00107 
00108 int my_register_filename(int fd, const char *FileName, uint32_t error_message_number, myf MyFlags)
00109 {
00110   if (fd >= 0)
00111     return fd;
00112   if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
00113   {
00114     if (errno == EMFILE)
00115       error_message_number= EE_OUT_OF_FILERESOURCES;
00116     my_error(static_cast<drizzled::error_t>(error_message_number), MYF(ME_BELL+ME_WAITTANG), FileName, errno);
00117   }
00118   return -1;
00119 }
00120 
00121 } /* namespace internal */
00122 } /* namespace drizzled */