~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
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"
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
19
#include "drizzled/my_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
{
1 by brian
clean slate
26
27
	/* Write a chunk of bytes to a file */
28
481 by Brian Aker
Remove all of uchar.
29
size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
1 by brian
clean slate
30
{
31
  size_t writenbytes, written;
482 by Brian Aker
Remove uint.
32
  uint32_t errors;
1 by brian
clean slate
33
  errors=0; written=0;
34
35
  /* The behavior of write(fd, buf, 0) is not portable */
36
  if (unlikely(!Count))
51.3.15 by Jay Pipes
Phase 3 removal of DBUG in mysys
37
    return(0);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
38
1 by brian
clean slate
39
  for (;;)
40
  {
41
    if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
42
      break;
43
    if (writenbytes != (size_t) -1)
44
    {						/* Safeguard */
45
      written+=writenbytes;
46
      Buffer+=writenbytes;
47
      Count-=writenbytes;
48
    }
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
49
    errno=errno;
1 by brian
clean slate
50
#ifndef NO_BACKGROUND
51
    if (my_thread_var->abort)
52
      MyFlags&= ~ MY_WAIT_IF_FULL;		/* End if aborted by user */
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
53
    if ((errno == ENOSPC || errno == EDQUOT) &&
1 by brian
clean slate
54
        (MyFlags & MY_WAIT_IF_FULL))
55
    {
56
      if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
57
	my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
58
		 "unknown", errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
398.1.10 by Monty Taylor
Actually removed VOID() this time.
59
      sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
1 by brian
clean slate
60
      continue;
61
    }
62
63
    if ((writenbytes == 0 || writenbytes == (size_t) -1))
64
    {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
65
      if (errno == EINTR)
1 by brian
clean slate
66
      {
67
        continue;                               /* Interrupted */
68
      }
69
70
      if (!writenbytes && !errors++)		/* Retry once */
71
      {
72
        /* We may come here if the file quota is exeeded */
73
        errno=EFBIG;				/* Assume this is the error */
74
        continue;
75
      }
76
    }
77
    else
78
      continue;					/* Retry */
79
#endif
80
    if (MyFlags & (MY_NABP | MY_FNABP))
81
    {
82
      if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
83
      {
84
	my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
85
		 "unknown", errno);
1 by brian
clean slate
86
      }
51.3.15 by Jay Pipes
Phase 3 removal of DBUG in mysys
87
      return(MY_FILE_ERROR);		/* Error on read */
1 by brian
clean slate
88
    }
89
    else
90
      break;					/* Return bytes written */
91
  }
92
  if (MyFlags & (MY_NABP | MY_FNABP))
51.3.15 by Jay Pipes
Phase 3 removal of DBUG in mysys
93
    return(0);			/* Want only errors */
94
  return(writenbytes+written);
1 by brian
clean slate
95
} /* my_write */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
96
97
} /* namespace internal */
98
} /* namespace drizzled */