Drizzled Public API Documentation

my_write.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/internal/thread_var.h>
00020 #include <drizzled/error.h>
00021 #include <cerrno>
00022 
00023 namespace drizzled
00024 {
00025 namespace internal
00026 {
00027 
00028   /* Write a chunk of bytes to a file */
00029 
00030 size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
00031 {
00032   size_t writenbytes, written;
00033   uint32_t errors;
00034   errors=0; written=0;
00035 
00036   /* The behavior of write(fd, buf, 0) is not portable */
00037   if (unlikely(!Count))
00038     return(0);
00039 
00040   for (;;)
00041   {
00042     if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
00043       break;
00044     if (writenbytes != (size_t) -1)
00045     {           /* Safeguard */
00046       written+=writenbytes;
00047       Buffer+=writenbytes;
00048       Count-=writenbytes;
00049     }
00050     errno=errno;
00051     if (MyFlags & (MY_NABP | MY_FNABP))
00052     {
00053       if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
00054       {
00055   my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
00056      "unknown", errno);
00057       }
00058       return(MY_FILE_ERROR);    /* Error on read */
00059     }
00060     else
00061       break;          /* Return bytes written */
00062   }
00063   if (MyFlags & (MY_NABP | MY_FNABP))
00064     return(0);      /* Want only errors */
00065   return(writenbytes+written);
00066 } /* my_write */
00067 
00068 } /* namespace internal */
00069 } /* namespace drizzled */