~drizzle-trunk/drizzle/development

« 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:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include "config.h"
17
 
 
18
 
#include "drizzled/internal/my_sys.h"
19
 
#include "drizzled/error.h"
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysys_priv.h"
 
17
#include "mysys_err.h"
20
18
#include <errno.h>
21
19
 
22
 
namespace drizzled
23
 
{
24
 
namespace internal
25
 
{
26
 
 
27
20
 
28
21
/*
29
22
  Read a chunk of bytes from a file with retry's if needed
40
33
      N  number of bytes read.
41
34
*/
42
35
 
43
 
size_t my_read(int Filedes, unsigned char *Buffer, size_t Count, myf MyFlags)
 
36
size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
44
37
{
45
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));
46
42
  save_count= Count;
47
43
 
48
44
  for (;;)
50
46
    errno= 0;                                   /* Linux doesn't reset this */
51
47
    if ((readbytes= read(Filedes, Buffer, Count)) != Count)
52
48
    {
53
 
      errno= errno ? errno : -1;
 
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
54
      if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
55
 
      {
 
55
      {  
 
56
        DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld",
 
57
                             (long) readbytes));
56
58
        continue;                              /* Interrupted */
57
59
      }
 
60
#endif
58
61
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
59
62
      {
60
63
        if (readbytes == (size_t) -1)
61
64
          my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
62
 
                   "unknown", errno);
 
65
                   my_filename(Filedes),my_errno);
63
66
        else if (MyFlags & (MY_NABP | MY_FNABP))
64
67
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
65
 
                   "unknown", errno);
 
68
                   my_filename(Filedes),my_errno);
66
69
      }
67
70
      if (readbytes == (size_t) -1 ||
68
71
          ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
69
 
        return(MY_FILE_ERROR);  /* Return with error */
 
72
        DBUG_RETURN(MY_FILE_ERROR);     /* Return with error */
70
73
      if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
71
74
      {
72
75
        Buffer+= readbytes;
81
84
      readbytes= save_count;
82
85
    break;
83
86
  }
84
 
  return(readbytes);
 
87
  DBUG_RETURN(readbytes);
85
88
} /* my_read */
86
 
 
87
 
} /* namespace internal */
88
 
} /* namespace drizzled */