~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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
16
#include <config.h>
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
17
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
18
#include <drizzled/internal/my_sys.h>
19
#include <drizzled/error.h>
685.1.3 by Monty Taylor
Turned off stdinc - and then fixed the carnage.
20
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
21
#include <fcntl.h>
22
23
#include <cerrno>
24
#include <cstdlib>
25
#include <cstring>
1 by brian
clean slate
26
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
27
28
namespace drizzled
29
{
30
namespace internal
31
{
32
1 by brian
clean slate
33
/*
34
  Open a file
35
36
  SYNOPSIS
37
    my_open()
38
      FileName	Fully qualified file name
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
39
      Flags	Read | write
1 by brian
clean slate
40
      MyFlags	Special flags
41
42
  RETURN VALUE
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
43
    int descriptor
1 by brian
clean slate
44
*/
45
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
46
int my_open(const char *FileName, int Flags, myf MyFlags)
1 by brian
clean slate
47
				/* Path-name of file */
48
				/* Read | write .. */
49
				/* Special flags */
50
{
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
51
  int fd;
1 by brian
clean slate
52
53
#if !defined(NO_OPEN_3)
54
  fd = open(FileName, Flags, my_umask);	/* Normal unix */
55
#else
56
  fd = open((char *) FileName, Flags);
57
#endif
58
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
59
  return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags));
1 by brian
clean slate
60
} /* my_open */
61
62
63
/*
64
  Close a file
65
66
  SYNOPSIS
67
    my_close()
68
      fd	File sescriptor
69
      myf	Special Flags
70
71
*/
72
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
73
int my_close(int fd, myf MyFlags)
1 by brian
clean slate
74
{
75
  int err;
76
77
  do
78
  {
79
    err= close(fd);
80
  } while (err == -1 && errno == EINTR);
81
82
  if (err)
83
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
84
    errno=errno;
1 by brian
clean slate
85
    if (MyFlags & (MY_FAE | MY_WME))
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
86
      my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
1 by brian
clean slate
87
  }
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
88
51.3.18 by Jay Pipes
Phase 5 - Remove DBUG from mysys
89
  return(err);
1 by brian
clean slate
90
} /* my_close */
91
92
93
/*
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
94
  TODO: Get rid of
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
95
1 by brian
clean slate
96
  SYNOPSIS
97
    my_register_filename()
98
    fd			   File number opened, -1 if error on open
99
    FileName		   File name
100
    type_file_type	   How file was created
101
    error_message_number   Error message number if caller got error (fd == -1)
102
    MyFlags		   Flags for my_close()
103
104
  RETURN
105
    -1   error
106
     #   Filenumber
107
108
*/
109
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
110
int my_register_filename(int fd, const char *FileName, uint32_t error_message_number, myf MyFlags)
1 by brian
clean slate
111
{
2241.2.10 by Olaf van der Spek
Refactor
112
  if (fd >= 0)
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
113
    return fd;
1 by brian
clean slate
114
  if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
115
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
116
    if (errno == EMFILE)
1 by brian
clean slate
117
      error_message_number= EE_OUT_OF_FILERESOURCES;
2241.2.10 by Olaf van der Spek
Refactor
118
    my_error(static_cast<drizzled::error_t>(error_message_number), MYF(ME_BELL+ME_WAITTANG), FileName, errno);
1 by brian
clean slate
119
  }
1034.1.8 by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not
120
  return -1;
121
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
122
123
} /* namespace internal */
124
} /* namespace drizzled */