FILE *my_fopen(const char *filename, int flags, myf MyFlags) { FILE *fd; char type[5]; char *dup_filename= NULL; DBUG_ENTER("my_fopen"); DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d", filename, flags, MyFlags)); make_ftype(type,flags); #ifdef _WIN32 fd= my_win_fopen(filename, type); #else fd= fopen(filename, type); #endif if (fd != 0) { /* The test works if MY_NFILE < 128. The problem is that fileno() is char on some OS (SUNOS). Actually the filename save isn't that important so we can ignore if this doesn't work. */ int filedesc= my_fileno(fd); if ((uint)filedesc >= my_file_limit) { mysql_mutex_lock(&THR_LOCK_open); my_stream_opened++; mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } dup_filename= my_strdup(key_memory_my_file_info, filename, MyFlags); if (dup_filename != NULL) { mysql_mutex_lock(&THR_LOCK_open); my_file_info[filedesc].name= dup_filename; my_stream_opened++; my_file_total_opened++; my_file_info[filedesc].type= STREAM_BY_FOPEN; mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } (void) my_fclose(fd,MyFlags); set_my_errno(ENOMEM); } else set_my_errno(errno); DBUG_PRINT("error",("Got error %d on open",my_errno())); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND : EE_CANTCREATEFILE, MYF(0), filename, my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); } DBUG_RETURN((FILE*) 0); } /* my_fopen */
FILE *my_fopen(const char *filename, int flags, myf MyFlags) { FILE *fd; char type[5]; DBUG_ENTER("my_fopen"); DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d", filename, flags, MyFlags)); make_ftype(type,flags); #ifdef _WIN32 fd= my_win_fopen(filename, type); #else fd= fopen(filename, type); #endif if (fd != 0) { /* The test works if MY_NFILE < 128. The problem is that fileno() is char on some OS (SUNOS). Actually the filename save isn't that important so we can ignore if this doesn't work. */ int filedesc= my_fileno(fd); if ((uint)filedesc >= my_file_limit) { thread_safe_increment(my_stream_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } mysql_mutex_lock(&THR_LOCK_open); if ((my_file_info[filedesc].name= (char*) my_strdup(filename,MyFlags))) { my_stream_opened++; my_file_total_opened++; my_file_info[filedesc].type= STREAM_BY_FOPEN; mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } mysql_mutex_unlock(&THR_LOCK_open); (void) my_fclose(fd,MyFlags); my_errno=ENOMEM; } else my_errno=errno; DBUG_PRINT("error",("Got error %d on open",my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND : EE_CANTCREATEFILE, MYF(ME_BELL+ME_WAITTANG), filename, my_errno); DBUG_RETURN((FILE*) 0); } /* my_fopen */