~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
16
#include "drizzled/internal/mysys_priv.h"
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
17
#include "drizzled/my_error.h"
1 by brian
clean slate
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
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
36
size_t my_read(int Filedes, unsigned char *Buffer, size_t Count, myf MyFlags)
1 by brian
clean slate
37
{
38
  size_t readbytes, save_count;
39
  save_count= Count;
40
41
  for (;;)
42
  {
43
    errno= 0;					/* Linux doesn't reset this */
44
    if ((readbytes= read(Filedes, Buffer, Count)) != Count)
45
    {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
46
      errno= errno ? errno : -1;
1 by brian
clean slate
47
      if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
48
      {
1 by brian
clean slate
49
        continue;                              /* Interrupted */
50
      }
51
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
52
      {
53
        if (readbytes == (size_t) -1)
54
          my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
55
                   "unknown", errno);
1 by brian
clean slate
56
        else if (MyFlags & (MY_NABP | MY_FNABP))
57
          my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
58
                   "unknown", errno);
1 by brian
clean slate
59
      }
60
      if (readbytes == (size_t) -1 ||
61
          ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
62
        return(MY_FILE_ERROR);	/* Return with error */
1 by brian
clean slate
63
      if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
64
      {
65
        Buffer+= readbytes;
66
        Count-= readbytes;
67
        continue;
68
      }
69
    }
70
71
    if (MyFlags & (MY_NABP | MY_FNABP))
72
      readbytes= 0;			/* Ok on read */
73
    else if (MyFlags & MY_FULL_IO)
74
      readbytes= save_count;
75
    break;
76
  }
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
77
  return(readbytes);
1 by brian
clean slate
78
} /* my_read */