41
DBUG_ENTER("my_fopen");
42
DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d",
43
filename, flags, MyFlags));
42
45
if we are not creating, then we need to use my_access to make sure
43
46
the file exists since Windows doesn't handle files like "com1.sym"
58
61
if ((uint) fileno(fd) >= my_file_limit)
60
63
thread_safe_increment(my_stream_opened,&THR_LOCK_open);
61
return(fd); /* safeguard */
64
DBUG_RETURN(fd); /* safeguard */
63
66
pthread_mutex_lock(&THR_LOCK_open);
64
67
if ((my_file_info[fileno(fd)].name = (char*)
68
71
my_file_total_opened++;
69
72
my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
70
73
pthread_mutex_unlock(&THR_LOCK_open);
74
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
73
77
pthread_mutex_unlock(&THR_LOCK_open);
74
78
(void) my_fclose(fd,MyFlags);
83
DBUG_PRINT("error",("Got error %d on open",my_errno));
79
84
if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
80
85
my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
82
87
MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
88
DBUG_RETURN((FILE*) 0);
89
94
int my_fclose(FILE *fd, myf MyFlags)
97
DBUG_ENTER("my_fclose");
98
DBUG_PRINT("my",("stream: 0x%lx MyFlags: %d", (long) fd, MyFlags));
93
100
pthread_mutex_lock(&THR_LOCK_open);
104
111
if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
106
113
my_file_info[file].type = UNOPEN;
107
free(my_file_info[file].name);
114
my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
109
116
pthread_mutex_unlock(&THR_LOCK_open);
111
118
} /* my_fclose */
121
/* Make a stream out of a file handle */
124
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
128
DBUG_ENTER("my_fdopen");
129
DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d",
130
Filedes, Flags, MyFlags));
132
make_ftype(type,Flags);
133
if ((fd = fdopen(Filedes, type)) == 0)
136
if (MyFlags & (MY_FAE | MY_WME))
137
my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno);
141
pthread_mutex_lock(&THR_LOCK_open);
143
if ((uint) Filedes < (uint) my_file_limit)
145
if (my_file_info[Filedes].type != UNOPEN)
147
my_file_opened--; /* File is opened with my_open ! */
151
my_file_info[Filedes].name= my_strdup(name,MyFlags);
153
my_file_info[Filedes].type = STREAM_BY_FDOPEN;
155
pthread_mutex_unlock(&THR_LOCK_open);
158
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
116
164
Make a fopen() typestring from a open() type bitmap
140
188
static void make_ftype(register char * to, register int flag)
142
190
/* check some possible invalid combinations */
143
assert((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
144
assert((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
191
DBUG_ASSERT((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
192
DBUG_ASSERT((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
146
194
if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
147
195
*to++= (flag & O_APPEND) ? 'a' : 'w';