~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/my_pread.cc

  • Committer: Brian Aker
  • Date: 2010-02-10 18:04:24 UTC
  • mfrom: (1286.1.5 build)
  • Revision ID: brian@gaz-20100210180424-03ypoyifmlc2lgcp
Merge of Brian/Padraig

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