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)); /* if we are not creating, then we need to use my_access to make sure the file exists since Windows doesn't handle files like "com1.sym" very well */ #ifdef __WIN__ if (check_if_legal_filename(filename)) { errno= EACCES; fd= 0; } else #endif { make_ftype(type,flags); fd = fopen(filename, type); } 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. */ if ((uint) fileno(fd) >= my_file_limit) { thread_safe_increment(my_stream_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } pthread_mutex_lock(&THR_LOCK_open); if ((my_file_info[fileno(fd)].name = (char*) my_strdup(filename,MyFlags))) { my_stream_opened++; my_file_info[fileno(fd)].type = STREAM_BY_FOPEN; pthread_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } pthread_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 */
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 */
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { FILE *fd; char type[5]; DBUG_ENTER("my_fdopen"); DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d", Filedes, Flags, MyFlags)); make_ftype(type,Flags); #ifdef _WIN32 fd= my_win_fdopen(Filedes, type); #else fd= fdopen(Filedes, type); #endif if (!fd) { set_my_errno(errno); if (MyFlags & (MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_CANT_OPEN_STREAM, MYF(0), my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); } } else { mysql_mutex_lock(&THR_LOCK_open); my_stream_opened++; if ((uint) Filedes < (uint) my_file_limit) { if (my_file_info[Filedes].type != UNOPEN) { my_file_opened--; /* File is opened with my_open ! */ } else { my_file_info[Filedes].name= my_strdup(key_memory_my_file_info, name,MyFlags); } my_file_info[Filedes].type = STREAM_BY_FDOPEN; } mysql_mutex_unlock(&THR_LOCK_open); } DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } /* my_fdopen */
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) { FILE *fd; char type[5]; DBUG_ENTER("my_fdopen"); DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d", Filedes, Flags, MyFlags)); make_ftype(type,Flags); if ((fd = fdopen(Filedes, type)) == 0) { my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); } else { pthread_mutex_lock(&THR_LOCK_open); my_stream_opened++; if ((uint) Filedes < (uint) my_file_limit) { if (my_file_info[Filedes].type != UNOPEN) { my_file_opened--; /* File is opened with my_open ! */ } else { my_file_info[Filedes].name= my_strdup(name,MyFlags); } my_file_info[Filedes].type = STREAM_BY_FDOPEN; } pthread_mutex_unlock(&THR_LOCK_open); } DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } /* my_fdopen */