~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/my_pread.cc

  • Committer: Stewart Smith
  • Date: 2009-08-20 17:15:54 UTC
  • mto: (1119.2.2 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090820171554-72eo1tqlc4n64rak
Valgrind 3.5 requires --alignment to be a power of 2 between 16 and 4096. The specifying --alignment is not important for us, so remove it.

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 "myisam_priv.h"
17
 
#include "drizzled/error.h"
18
 
#include <cerrno>
 
16
#include "myisamdef.h"
 
17
#include <mysys/mysys_err.h>
 
18
#include <errno.h>
19
19
#include <unistd.h>
20
20
 
21
 
using namespace drizzled;
22
 
 
23
21
/*
24
22
  Read a chunk of bytes from a file from a given position
25
23
 
41
39
    #             Number of bytes read
42
40
*/
43
41
 
44
 
size_t my_pread(int Filedes, unsigned char *Buffer, size_t Count, internal::my_off_t offset,
 
42
size_t my_pread(File Filedes, unsigned char *Buffer, size_t Count, my_off_t offset,
45
43
                myf MyFlags)
46
44
{
47
45
  size_t readbytes;
50
48
  {
51
49
    errno=0;                                    /* Linux doesn't reset this */
52
50
    if ((error= ((readbytes= pread(Filedes, Buffer, Count, offset)) != Count)))
53
 
      errno= errno ? errno : -1;
 
51
      my_errno= errno ? errno : -1;
54
52
    if (error || readbytes != Count)
55
53
    {
56
54
      if ((readbytes == 0 || readbytes == (size_t) -1) && errno == EINTR)
60
58
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
61
59
      {
62
60
        if (readbytes == (size_t) -1)
63
 
          my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
 
61
          my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), "unknown", my_errno);
64
62
        else if (MyFlags & (MY_NABP | MY_FNABP))
65
 
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
 
63
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), "unknown", my_errno);
66
64
      }
67
65
      if (readbytes == (size_t) -1 || (MyFlags & (MY_FNABP | MY_NABP)))
68
66
        return(MY_FILE_ERROR);          /* Return with error */
69
67
    }
70
68
    if (MyFlags & (MY_NABP | MY_FNABP))
71
69
      return(0);                                /* Read went ok; Return 0 */
72
 
    return(readbytes);
 
70
    return(readbytes);                  /* purecov: inspected */
73
71
  }
74
72
} /* my_pread */
75
73
 
96
94
*/
97
95
 
98
96
size_t my_pwrite(int Filedes, const unsigned char *Buffer, size_t Count,
99
 
                 internal::my_off_t offset, myf MyFlags)
 
97
                 my_off_t offset, myf MyFlags)
100
98
{
101
99
  size_t writenbytes, written;
102
100
  uint32_t errors;
107
105
  {
108
106
    if ((writenbytes= pwrite(Filedes, Buffer, Count,offset)) == Count)
109
107
      break;
110
 
    errno= errno;
 
108
    my_errno= errno;
111
109
    if (writenbytes != (size_t) -1)
112
110
    {                                   /* Safegueard */
113
111
      written+=writenbytes;
118
116
#ifndef NO_BACKGROUND
119
117
    if (my_thread_var->abort)
120
118
      MyFlags&= ~ MY_WAIT_IF_FULL;              /* End if aborted by user */
121
 
    if ((errno == ENOSPC || errno == EDQUOT) &&
 
119
    if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
122
120
        (MyFlags & MY_WAIT_IF_FULL))
123
121
    {
124
122
      if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
125
123
        my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
126
 
                 "unknown", errno, MY_WAIT_FOR_USER_TO_FIX_PANIC);
 
124
                 "unknown", my_errno, MY_WAIT_FOR_USER_TO_FIX_PANIC);
127
125
      sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
128
126
      continue;
129
127
    }
130
 
    if ((writenbytes && writenbytes != (size_t) -1) || errno == EINTR)
 
128
    if ((writenbytes && writenbytes != (size_t) -1) || my_errno == EINTR)
131
129
      continue;                                 /* Retry */
132
130
#endif
133
131
    if (MyFlags & (MY_NABP | MY_FNABP))
134
132
    {
135
133
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
136
134
      {
137
 
        my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), "unknown", errno);
 
135
        my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), "unknown", my_errno);
138
136
      }
139
137
      return(MY_FILE_ERROR);            /* Error on read */
140
138
    }
143
141
  }
144
142
  if (MyFlags & (MY_NABP | MY_FNABP))
145
143
    return(0);                  /* Want only errors */
146
 
  return(writenbytes+written);
 
144
  return(writenbytes+written); /* purecov: inspected */
147
145
} /* my_pwrite */