Drizzled Public API Documentation

my_write.cc
1 /* Copyright (C) 2000 MySQL AB
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include <config.h>
17 
18 #include <drizzled/internal/my_sys.h>
19 #include <drizzled/internal/thread_var.h>
20 #include <drizzled/error.h>
21 #include <cerrno>
22 
23 namespace drizzled
24 {
25 namespace internal
26 {
27 
28  /* Write a chunk of bytes to a file */
29 
30 size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
31 {
32  size_t writenbytes, written;
33  written=0;
34 
35  /* The behavior of write(fd, buf, 0) is not portable */
36  if (unlikely(!Count))
37  return 0;
38 
39  for (;;)
40  {
41  if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
42  break;
43  if (writenbytes != (size_t) -1)
44  { /* Safeguard */
45  written+=writenbytes;
46  Buffer+=writenbytes;
47  Count-=writenbytes;
48  }
49  errno=errno;
50  if (MyFlags & (MY_NABP | MY_FNABP))
51  {
52  if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
53  {
54  my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
55  "unknown", errno);
56  }
57  return(MY_FILE_ERROR); /* Error on read */
58  }
59  else
60  break; /* Return bytes written */
61  }
62  if (MyFlags & (MY_NABP | MY_FNABP))
63  return 0; /* Want only errors */
64  return(writenbytes+written);
65 } /* my_write */
66 
67 } /* namespace internal */
68 } /* namespace drizzled */