16 #include "mysys_priv.h"
17 #include "mysys_err.h"
35 File my_open(
const char *FileName,
int Flags, myf MyFlags)
41 DBUG_ENTER(
"my_open");
42 DBUG_PRINT(
"my",(
"Name: '%s' Flags: %d MyFlags: %d",
43 FileName, Flags, MyFlags));
45 fd= my_win_open(FileName, Flags);
46 #elif !defined(NO_OPEN_3)
47 fd = open(FileName, Flags, my_umask);
49 fd = open((
char *) FileName, Flags);
52 fd= my_register_filename(fd, FileName, FILE_BY_OPEN, EE_FILENOTFOUND, MyFlags);
67 int my_close(File fd, myf MyFlags)
70 DBUG_ENTER(
"my_close");
71 DBUG_PRINT(
"my",(
"fd: %d MyFlags: %d",fd, MyFlags));
78 }
while (err == -1 && errno == EINTR);
80 err= my_win_close(fd);
84 DBUG_PRINT(
"error",(
"Got error %d on close",err));
86 if (MyFlags & (MY_FAE | MY_WME))
88 char errbuf[MYSYS_STRERROR_SIZE];
89 my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), my_filename(fd),
90 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
93 if ((uint) fd < my_file_limit && my_file_info[fd].
type != UNOPEN)
95 my_free(my_file_info[fd].
name);
96 #if !defined(HAVE_PREAD) && !defined(_WIN32)
99 my_file_info[fd].type = UNOPEN;
124 File my_register_filename(File fd,
const char *FileName,
enum file_type
125 type_of_file, uint error_message_number, myf MyFlags)
127 DBUG_ENTER(
"my_register_filename");
128 if ((
int) fd >= MY_FILE_MIN)
130 if ((uint) fd >= my_file_limit)
132 #if !defined(HAVE_PREAD)
135 thread_safe_increment(my_file_opened,&THR_LOCK_open);
142 if ((my_file_info[fd].
name = (
char*) my_strdup(FileName,MyFlags)))
145 my_file_total_opened++;
146 my_file_info[fd].type = type_of_file;
147 #if !defined(HAVE_PREAD) && !defined(_WIN32)
152 DBUG_PRINT(
"exit",(
"fd: %d",fd));
158 (void) my_close(fd, MyFlags);
163 DBUG_PRINT(
"error",(
"Got error %d on open", my_errno));
164 if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
166 char errbuf[MYSYS_STRERROR_SIZE];
167 if (my_errno == EMFILE)
168 error_message_number= EE_OUT_OF_FILERESOURCES;
169 DBUG_PRINT(
"error",(
"print err: %d",error_message_number));
170 my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), FileName,
171 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
181 void my_print_open_files(
void)
183 if (my_file_opened | my_stream_opened)
186 for (i= 0 ; i < my_file_limit ; i++)
188 if (my_file_info[i].
type != UNOPEN)
190 fprintf(stderr, EE(EE_FILE_NOT_CLOSED), my_file_info[i].
name, i);