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