1
/* Copyright (C) 2000 MySQL AB
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.
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.
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 */
16
#include "mysys/mysys_priv.h"
17
#include "my_static.h"
18
#include "mysys/mysys_err.h"
25
static void make_ftype(char * to,int flag);
32
FileName Path-name of file
33
Flags Read | write | append | trunc (like for open())
34
MyFlags Flags for handling errors
41
FILE *my_fopen(const char *filename, int flags, myf MyFlags)
46
if we are not creating, then we need to use my_access to make sure
47
the file exists since Windows doesn't handle files like "com1.sym"
51
make_ftype(type,flags);
52
fd = fopen(filename, type);
58
return fd; /* safeguard */
62
if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
63
my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
65
MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
72
int my_fclose(FILE *fd, myf MyFlags)
77
if ((err = fclose(fd)) < 0)
80
if (MyFlags & (MY_FAE | MY_WME))
81
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),
82
my_filename(file),errno);
93
Make a fopen() typestring from a open() type bitmap
97
to String for fopen() is stored here
98
flag Flag used by open()
101
This routine attempts to find the best possible match
102
between a numeric option and a string option that could be
103
fed to fopen. There is not a 1 to 1 mapping between the two.
106
On Unix, O_RDONLY is usually 0
110
w == O_WRONLY|O_TRUNC|O_CREAT
111
a == O_WRONLY|O_APPEND|O_CREAT
113
w+ == O_RDWR|O_TRUNC|O_CREAT
114
a+ == O_RDWR|O_APPEND|O_CREAT
117
static void make_ftype(register char * to, register int flag)
119
/* check some possible invalid combinations */
120
assert((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
121
assert((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
123
if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
124
*to++= (flag & O_APPEND) ? 'a' : 'w';
125
else if (flag & O_RDWR)
127
/* Add '+' after theese */
128
if (flag & (O_TRUNC | O_CREAT))
130
else if (flag & O_APPEND)