~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/my_pread.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

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),
 
62
                   my_filename(Filedes),my_errno);
64
63
        else if (MyFlags & (MY_NABP | MY_FNABP))
65
 
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
 
64
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
 
65
                   my_filename(Filedes),my_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);
 
72
    return(readbytes);                  /* purecov: inspected */
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
 
                 internal::my_off_t offset, myf MyFlags)
 
99
                 my_off_t offset, myf MyFlags)
100
100
{
101
101
  size_t writenbytes, written;
102
102
  uint32_t errors;
107
107
  {
108
108
    if ((writenbytes= pwrite(Filedes, Buffer, Count,offset)) == Count)
109
109
      break;
110
 
    errno= errno;
 
110
    my_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 ((errno == ENOSPC || errno == EDQUOT) &&
 
121
    if ((my_errno == ENOSPC || my_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
 
                 "unknown", errno, MY_WAIT_FOR_USER_TO_FIX_PANIC);
 
126
                 my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
127
127
      sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
128
128
      continue;
129
129
    }
130
 
    if ((writenbytes && writenbytes != (size_t) -1) || errno == EINTR)
 
130
    if ((writenbytes && writenbytes != (size_t) -1) || my_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), "unknown", errno);
 
137
        my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG),
 
138
                 my_filename(Filedes),my_errno);
138
139
      }
139
140
      return(MY_FILE_ERROR);            /* Error on read */
140
141
    }
143
144
  }
144
145
  if (MyFlags & (MY_NABP | MY_FNABP))
145
146
    return(0);                  /* Want only errors */
146
 
  return(writenbytes+written);
 
147
  return(writenbytes+written); /* purecov: inspected */
147
148
} /* my_pwrite */