drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
my_open.cc
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16#include <config.h>
17
18#include <drizzled/internal/my_sys.h>
19#include <drizzled/error.h>
20
21#include <fcntl.h>
22
23#include <cerrno>
24#include <cstdlib>
25#include <cstring>
26
27
28namespace drizzled {
29namespace internal {
30
31/*
32 Open a file
33
34 SYNOPSIS
35 my_open()
36 FileName Fully qualified file name
37 Flags Read | write
38 MyFlags Special flags
39
40 RETURN VALUE
41 int descriptor
42*/
43
44int my_open(const char *FileName, int Flags, myf MyFlags)
45 /* Path-name of file */
46 /* Read | write .. */
47 /* Special flags */
48{
49 int fd;
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
57 return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags));
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
71int my_close(int fd, myf MyFlags)
72{
73 int err;
74
75 do
76 {
77 err= close(fd);
78 } while (err == -1 && errno == EINTR);
79
80 if (err)
81 {
82 errno=errno;
83 if (MyFlags & (MY_FAE | MY_WME))
84 my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
85 }
86
87 return(err);
88} /* my_close */
89
90
91/*
92 TODO: Get rid of
93
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
108int my_register_filename(int fd, const char *FileName, uint32_t error_message_number, myf MyFlags)
109{
110 if (fd >= 0)
111 return fd;
112 if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
113 {
114 if (errno == EMFILE)
115 error_message_number= EE_OUT_OF_FILERESOURCES;
116 my_error(static_cast<drizzled::error_t>(error_message_number), MYF(ME_BELL+ME_WAITTANG), FileName, errno);
117 }
118 return -1;
119}
120
121} /* namespace internal */
122} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.