~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysys/my_read.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysys_priv.h"
 
17
#include "mysys_err.h"
 
18
#include <errno.h>
 
19
 
 
20
 
 
21
/*
 
22
  Read a chunk of bytes from a file with retry's if needed
 
23
 
 
24
  The parameters are:
 
25
    File descriptor
 
26
    Buffer to hold at least Count bytes
 
27
    Bytes to read
 
28
    Flags on what to do on error
 
29
 
 
30
    Return:
 
31
      -1 on error
 
32
      0  if flag has bits MY_NABP or MY_FNABP set
 
33
      N  number of bytes read.
 
34
*/
 
35
 
 
36
size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
 
37
{
 
38
  size_t readbytes, save_count;
 
39
  DBUG_ENTER("my_read");
 
40
  DBUG_PRINT("my",("Fd: %d  Buffer: 0x%lx  Count: %lu  MyFlags: %d",
 
41
                   Filedes, (long) Buffer, (ulong) Count, MyFlags));
 
42
  save_count= Count;
 
43
 
 
44
  for (;;)
 
45
  {
 
46
    errno= 0;                                   /* Linux doesn't reset this */
 
47
    if ((readbytes= read(Filedes, Buffer, Count)) != Count)
 
48
    {
 
49
      my_errno= errno ? errno : -1;
 
50
      DBUG_PRINT("warning",("Read only %d bytes off %lu from %d, errno: %d",
 
51
                            (int) readbytes, (ulong) Count, Filedes,
 
52
                            my_errno));
 
53
#ifdef THREAD
 
54
      if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
 
55
      {  
 
56
        DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld",
 
57
                             (long) readbytes));
 
58
        continue;                              /* Interrupted */
 
59
      }
 
60
#endif
 
61
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
 
62
      {
 
63
        if (readbytes == (size_t) -1)
 
64
          my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
 
65
                   my_filename(Filedes),my_errno);
 
66
        else if (MyFlags & (MY_NABP | MY_FNABP))
 
67
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
 
68
                   my_filename(Filedes),my_errno);
 
69
      }
 
70
      if (readbytes == (size_t) -1 ||
 
71
          ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
 
72
        DBUG_RETURN(MY_FILE_ERROR);     /* Return with error */
 
73
      if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
 
74
      {
 
75
        Buffer+= readbytes;
 
76
        Count-= readbytes;
 
77
        continue;
 
78
      }
 
79
    }
 
80
 
 
81
    if (MyFlags & (MY_NABP | MY_FNABP))
 
82
      readbytes= 0;                     /* Ok on read */
 
83
    else if (MyFlags & MY_FULL_IO)
 
84
      readbytes= save_count;
 
85
    break;
 
86
  }
 
87
  DBUG_RETURN(readbytes);
 
88
} /* my_read */