~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_write.c

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
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
 
{
 
16
#include "mysys_priv.h"
 
17
#include "mysys_err.h"
 
18
#include <errno.h>
 
19
 
27
20
 
28
21
        /* Write a chunk of bytes to a file */
29
22
 
30
 
size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
 
23
size_t my_write(int Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
31
24
{
32
25
  size_t writenbytes, written;
33
 
  uint32_t errors;
 
26
  uint errors;
 
27
  DBUG_ENTER("my_write");
 
28
  DBUG_PRINT("my",("Fd: %d  Buffer: 0x%lx  Count: %lu  MyFlags: %d",
 
29
                   Filedes, (long) Buffer, (ulong) Count, MyFlags));
34
30
  errors=0; written=0;
35
31
 
36
32
  /* The behavior of write(fd, buf, 0) is not portable */
37
33
  if (unlikely(!Count))
38
 
    return(0);
39
 
 
 
34
    DBUG_RETURN(0);
 
35
  
40
36
  for (;;)
41
37
  {
42
38
    if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
47
43
      Buffer+=writenbytes;
48
44
      Count-=writenbytes;
49
45
    }
50
 
    errno=errno;
 
46
    my_errno=errno;
 
47
    DBUG_PRINT("error",("Write only %ld bytes, error: %d",
 
48
                        (long) writenbytes, my_errno));
 
49
#ifndef NO_BACKGROUND
 
50
    if (my_thread_var->abort)
 
51
      MyFlags&= ~ MY_WAIT_IF_FULL;              /* End if aborted by user */
 
52
    if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
 
53
        (MyFlags & MY_WAIT_IF_FULL))
 
54
    {
 
55
      if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
 
56
        my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
 
57
                 my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
 
58
      VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
 
59
      continue;
 
60
    }
 
61
 
 
62
    if ((writenbytes == 0 || writenbytes == (size_t) -1))
 
63
    {
 
64
      if (my_errno == EINTR)
 
65
      {
 
66
        DBUG_PRINT("debug", ("my_write() was interrupted and returned %ld",
 
67
                             (long) writenbytes));
 
68
        continue;                               /* Interrupted */
 
69
      }
 
70
 
 
71
      if (!writenbytes && !errors++)            /* Retry once */
 
72
      {
 
73
        /* We may come here if the file quota is exeeded */
 
74
        errno=EFBIG;                            /* Assume this is the error */
 
75
        continue;
 
76
      }
 
77
    }
 
78
    else
 
79
      continue;                                 /* Retry */
 
80
#endif
51
81
    if (MyFlags & (MY_NABP | MY_FNABP))
52
82
    {
53
83
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
54
84
      {
55
85
        my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
56
 
                 "unknown", errno);
 
86
                 my_filename(Filedes),my_errno);
57
87
      }
58
 
      return(MY_FILE_ERROR);            /* Error on read */
 
88
      DBUG_RETURN(MY_FILE_ERROR);               /* Error on read */
59
89
    }
60
90
    else
61
91
      break;                                    /* Return bytes written */
62
92
  }
63
93
  if (MyFlags & (MY_NABP | MY_FNABP))
64
 
    return(0);                  /* Want only errors */
65
 
  return(writenbytes+written);
 
94
    DBUG_RETURN(0);                     /* Want only errors */
 
95
  DBUG_RETURN(writenbytes+written);
66
96
} /* my_write */
67
 
 
68
 
} /* namespace internal */
69
 
} /* namespace drizzled */