~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_write.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
        /* Write a chunk of bytes to a file */
22
22
 
23
 
size_t my_write(int Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
 
23
size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
24
24
{
25
25
  size_t writenbytes, written;
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));
 
26
  uint32_t errors;
30
27
  errors=0; written=0;
31
28
 
32
29
  /* The behavior of write(fd, buf, 0) is not portable */
33
30
  if (unlikely(!Count))
34
 
    DBUG_RETURN(0);
 
31
    return(0);
35
32
  
36
33
  for (;;)
37
34
  {
44
41
      Count-=writenbytes;
45
42
    }
46
43
    my_errno=errno;
47
 
    DBUG_PRINT("error",("Write only %ld bytes, error: %d",
48
 
                        (long) writenbytes, my_errno));
49
44
#ifndef NO_BACKGROUND
50
 
#ifdef THREAD
51
45
    if (my_thread_var->abort)
52
46
      MyFlags&= ~ MY_WAIT_IF_FULL;              /* End if aborted by user */
53
 
#endif
54
47
    if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
55
48
        (MyFlags & MY_WAIT_IF_FULL))
56
49
    {
57
50
      if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
58
51
        my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
59
52
                 my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
60
 
      VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
 
53
      sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
61
54
      continue;
62
55
    }
63
56
 
65
58
    {
66
59
      if (my_errno == EINTR)
67
60
      {
68
 
        DBUG_PRINT("debug", ("my_write() was interrupted and returned %ld",
69
 
                             (long) writenbytes));
70
61
        continue;                               /* Interrupted */
71
62
      }
72
63
 
87
78
        my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
88
79
                 my_filename(Filedes),my_errno);
89
80
      }
90
 
      DBUG_RETURN(MY_FILE_ERROR);               /* Error on read */
 
81
      return(MY_FILE_ERROR);            /* Error on read */
91
82
    }
92
83
    else
93
84
      break;                                    /* Return bytes written */
94
85
  }
95
86
  if (MyFlags & (MY_NABP | MY_FNABP))
96
 
    DBUG_RETURN(0);                     /* Want only errors */
97
 
  DBUG_RETURN(writenbytes+written);
 
87
    return(0);                  /* Want only errors */
 
88
  return(writenbytes+written);
98
89
} /* my_write */