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 |
||
994.2.4
by Monty Taylor
Blast. Fixed some make distcheck issues. |
16 |
#include "mysys/mysys_priv.h" |
17 |
#include "mysys/mysys_err.h" |
|
685.1.3
by Monty Taylor
Turned off stdinc - and then fixed the carnage. |
18 |
#include "my_dir.h" |
19 |
||
1
by brian
clean slate |
20 |
#include <errno.h> |
612.2.6
by Monty Taylor
OpenSolaris builds. |
21 |
#include <stdlib.h> |
656.1.26
by Monty Taylor
Finally removed all of the my_malloc stuff. |
22 |
#include <string.h> |
1
by brian
clean slate |
23 |
|
24 |
/*
|
|
25 |
Open a file
|
|
26 |
||
27 |
SYNOPSIS
|
|
28 |
my_open()
|
|
29 |
FileName Fully qualified file name
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
30 |
Flags Read | write
|
1
by brian
clean slate |
31 |
MyFlags Special flags
|
32 |
||
33 |
RETURN VALUE
|
|
34 |
File descriptor
|
|
35 |
*/
|
|
36 |
||
37 |
File my_open(const char *FileName, int Flags, myf MyFlags) |
|
38 |
/* Path-name of file */
|
|
39 |
/* Read | write .. */
|
|
40 |
/* Special flags */
|
|
41 |
{
|
|
42 |
File fd; |
|
43 |
||
44 |
#if !defined(NO_OPEN_3)
|
|
45 |
fd = open(FileName, Flags, my_umask); /* Normal unix */ |
|
46 |
#else
|
|
47 |
fd = open((char *) FileName, Flags); |
|
48 |
#endif
|
|
49 |
||
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
50 |
return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags)); |
1
by brian
clean slate |
51 |
} /* my_open */ |
52 |
||
53 |
||
54 |
/*
|
|
55 |
Close a file
|
|
56 |
||
57 |
SYNOPSIS
|
|
58 |
my_close()
|
|
59 |
fd File sescriptor
|
|
60 |
myf Special Flags
|
|
61 |
||
62 |
*/
|
|
63 |
||
64 |
int my_close(File fd, myf MyFlags) |
|
65 |
{
|
|
66 |
int err; |
|
67 |
||
68 |
do
|
|
69 |
{
|
|
70 |
err= close(fd); |
|
71 |
} while (err == -1 && errno == EINTR); |
|
72 |
||
73 |
if (err) |
|
74 |
{
|
|
75 |
my_errno=errno; |
|
76 |
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 |
77 |
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno); |
1
by brian
clean slate |
78 |
}
|
79 |
my_file_opened--; |
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
80 |
|
51.3.18
by Jay Pipes
Phase 5 - Remove DBUG from mysys |
81 |
return(err); |
1
by brian
clean slate |
82 |
} /* my_close */ |
83 |
||
84 |
||
85 |
/*
|
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
86 |
TODO: Get rid of
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
87 |
|
1
by brian
clean slate |
88 |
SYNOPSIS
|
89 |
my_register_filename()
|
|
90 |
fd File number opened, -1 if error on open
|
|
91 |
FileName File name
|
|
92 |
type_file_type How file was created
|
|
93 |
error_message_number Error message number if caller got error (fd == -1)
|
|
94 |
MyFlags Flags for my_close()
|
|
95 |
||
96 |
RETURN
|
|
97 |
-1 error
|
|
98 |
# Filenumber
|
|
99 |
||
100 |
*/
|
|
101 |
||
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
102 |
File my_register_filename(File fd, const char *FileName, uint32_t error_message_number, myf MyFlags) |
1
by brian
clean slate |
103 |
{
|
104 |
if ((int) fd >= 0) |
|
105 |
{
|
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
106 |
my_file_opened++; |
107 |
my_file_total_opened++; |
|
108 |
||
109 |
return fd; |
|
1
by brian
clean slate |
110 |
}
|
111 |
else
|
|
112 |
my_errno= errno; |
|
113 |
||
114 |
if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) |
|
115 |
{
|
|
116 |
if (my_errno == EMFILE) |
|
117 |
error_message_number= EE_OUT_OF_FILERESOURCES; |
|
118 |
my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), |
|
119 |
FileName, my_errno); |
|
120 |
}
|
|
1034.1.8
by Brian Aker
Remove locks around my_open(). Open file counts are now "best effort" (not |
121 |
return -1; |
122 |
}
|