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   written=0;
00034 
00035   /* The behavior of write(fd, buf, 0) is not portable */
00036   if (unlikely(!Count))
00037     return 0;
00038 
00039   for (;;)
00040   {
00041     if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
00042       break;
00043     if (writenbytes != (size_t) -1)
00044     {           /* Safeguard */
00045       written+=writenbytes;
00046       Buffer+=writenbytes;
00047       Count-=writenbytes;
00048     }
00049     errno=errno;
00050     if (MyFlags & (MY_NABP | MY_FNABP))
00051     {
00052       if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
00053       {
00054   my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
00055      "unknown", errno);
00056       }
00057       return(MY_FILE_ERROR);    /* Error on read */
00058     }
00059     else
00060       break;          /* Return bytes written */
00061   }
00062   if (MyFlags & (MY_NABP | MY_FNABP))
00063     return 0;     /* Want only errors */
00064   return(writenbytes+written);
00065 } /* my_write */
00066 
00067 } /* namespace internal */
00068 } /* namespace drizzled */