12
12
You should have received a copy of the GNU General Public License
13
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 */
18
#include "drizzled/internal/my_sys.h"
19
#include "drizzled/error.h"
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
38
26
FileName Fully qualified file name
40
28
MyFlags Special flags
46
int my_open(const char *FileName, int Flags, myf MyFlags)
34
File my_open(const char *FileName, int Flags, myf MyFlags)
47
35
/* Path-name of file */
48
36
/* Read | write .. */
49
37
/* Special flags */
53
41
#if !defined(NO_OPEN_3)
54
42
fd = open(FileName, Flags, my_umask); /* Normal unix */
56
44
fd = open((char *) FileName, Flags);
59
return(my_register_filename(fd, FileName, EE_FILENOTFOUND, MyFlags));
47
return(my_register_filename(fd, FileName, FILE_BY_OPEN,
48
EE_FILENOTFOUND, MyFlags));
85
75
if (MyFlags & (MY_FAE | MY_WME))
86
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), "unknown", errno);
76
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno);
78
if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN)
80
free(my_file_info[fd].name);
81
#if !defined(HAVE_PREAD)
82
pthread_mutex_destroy(&my_file_info[fd].mutex);
84
my_file_info[fd].type = UNOPEN;
87
pthread_mutex_unlock(&THR_LOCK_open);
93
Register file in my_file_info[]
97
96
my_register_filename()
98
97
fd File number opened, -1 if error on open
110
int my_register_filename(int fd, const char *FileName, uint32_t error_message_number, myf MyFlags)
109
File my_register_filename(File fd, const char *FileName, enum file_type
110
type_of_file, uint32_t error_message_number, myf MyFlags)
112
112
if ((int) fd >= 0)
114
if ((uint) fd >= my_file_limit)
116
#if !defined(HAVE_PREAD)
119
thread_safe_increment(my_file_opened,&THR_LOCK_open);
120
return(fd); /* safeguard */
125
pthread_mutex_lock(&THR_LOCK_open);
126
if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags)))
129
my_file_total_opened++;
130
my_file_info[fd].type = type_of_file;
131
#if !defined(HAVE_PREAD)
132
pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
134
pthread_mutex_unlock(&THR_LOCK_open);
137
pthread_mutex_unlock(&THR_LOCK_open);
140
(void) my_close(fd, MyFlags);
119
145
if (MyFlags & (MY_FFNF | MY_FAE | MY_WME))
147
if (my_errno == EMFILE)
122
148
error_message_number= EE_OUT_OF_FILERESOURCES;
123
my_error(static_cast<drizzled::error_t>(error_message_number), MYF(ME_BELL+ME_WAITTANG),
129
} /* namespace internal */
130
} /* namespace drizzled */
149
my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG),
158
void my_print_open_files(void)
160
if (my_file_opened | my_stream_opened)
163
for (i= 0 ; i < my_file_limit ; i++)
165
if (my_file_info[i].type != UNOPEN)
167
fprintf(stderr, EE(EE_FILE_NOT_CLOSED), my_file_info[i].name, i);