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