~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
16
#include "config.h"
17
18
#include "drizzled/internal/my_sys.h"
1271.5.3 by Tim Penhey
change the include files
19
#include "drizzled/error.h"
1 by brian
clean slate
20
#include <errno.h>
21
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
22
namespace drizzled
23
{
24
namespace internal
25
{
26
1 by brian
clean slate
27
28
/*
29
  Read a chunk of bytes from a file with retry's if needed
30
31
  The parameters are:
32
    File descriptor
33
    Buffer to hold at least Count bytes
34
    Bytes to read
35
    Flags on what to do on error
36
37
    Return:
38
      -1 on error
39
      0  if flag has bits MY_NABP or MY_FNABP set
40
      N  number of bytes read.
41
*/
42
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
43
size_t my_read(int Filedes, unsigned char *Buffer, size_t Count, myf MyFlags)
1 by brian
clean slate
44
{
45
  size_t readbytes, save_count;
46
  save_count= Count;
47
48
  for (;;)
49
  {
50
    errno= 0;					/* Linux doesn't reset this */
51
    if ((readbytes= read(Filedes, Buffer, Count)) != Count)
52
    {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
53
      errno= errno ? errno : -1;
1 by brian
clean slate
54
      if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
55
      {
1 by brian
clean slate
56
        continue;                              /* Interrupted */
57
      }
58
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
59
      {
60
        if (readbytes == (size_t) -1)
61
          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.
62
                   "unknown", errno);
1 by brian
clean slate
63
        else if (MyFlags & (MY_NABP | MY_FNABP))
64
          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.
65
                   "unknown", errno);
1 by brian
clean slate
66
      }
67
      if (readbytes == (size_t) -1 ||
68
          ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
69
        return(MY_FILE_ERROR);	/* Return with error */
1 by brian
clean slate
70
      if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
71
      {
72
        Buffer+= readbytes;
73
        Count-= readbytes;
74
        continue;
75
      }
76
    }
77
78
    if (MyFlags & (MY_NABP | MY_FNABP))
79
      readbytes= 0;			/* Ok on read */
80
    else if (MyFlags & MY_FULL_IO)
81
      readbytes= save_count;
82
    break;
83
  }
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
84
  return(readbytes);
1 by brian
clean slate
85
} /* my_read */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
86
87
} /* namespace internal */
88
} /* namespace drizzled */