| 39 | */ |
| 40 | |
| 41 | FILE *my_fopen(const char *filename, int flags, myf MyFlags) |
| 42 | { |
| 43 | FILE *fd; |
| 44 | char type[5]; |
| 45 | DBUG_ENTER("my_fopen"); |
| 46 | DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d", |
| 47 | filename, flags, MyFlags)); |
| 48 | |
| 49 | make_ftype(type,flags); |
| 50 | |
| 51 | #ifdef _WIN32 |
| 52 | fd= my_win_fopen(filename, type); |
| 53 | #else |
| 54 | fd= fopen(filename, type); |
| 55 | #endif |
| 56 | if (fd != 0) |
| 57 | { |
| 58 | /* |
| 59 | The test works if MY_NFILE < 128. The problem is that fileno() is char |
| 60 | on some OS (SUNOS). Actually the filename save isn't that important |
| 61 | so we can ignore if this doesn't work. |
| 62 | */ |
| 63 | |
| 64 | int filedesc= my_fileno(fd); |
| 65 | if ((uint)filedesc >= my_file_limit) |
| 66 | { |
| 67 | thread_safe_increment(my_stream_opened,&THR_LOCK_open); |
| 68 | DBUG_RETURN(fd); /* safeguard */ |
| 69 | } |
| 70 | mysql_mutex_lock(&THR_LOCK_open); |
| 71 | if ((my_file_info[filedesc].name= (char*) |
| 72 | my_strdup(filename,MyFlags))) |
| 73 | { |
| 74 | my_stream_opened++; |
| 75 | my_file_total_opened++; |
| 76 | my_file_info[filedesc].type= STREAM_BY_FOPEN; |
| 77 | mysql_mutex_unlock(&THR_LOCK_open); |
| 78 | DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); |
| 79 | DBUG_RETURN(fd); |
| 80 | } |
| 81 | mysql_mutex_unlock(&THR_LOCK_open); |
| 82 | (void) my_fclose(fd,MyFlags); |
| 83 | my_errno=ENOMEM; |
| 84 | } |
| 85 | else |
| 86 | my_errno=errno; |
| 87 | DBUG_PRINT("error",("Got error %d on open",my_errno)); |
| 88 | if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) |
| 89 | { |
| 90 | char errbuf[MYSYS_STRERROR_SIZE]; |
| 91 | my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND : |
| 92 | EE_CANTCREATEFILE, |
| 93 | MYF(ME_BELL+ME_WAITTANG), filename, |
| 94 | my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno)); |
| 95 | } |
| 96 | DBUG_RETURN((FILE*) 0); |
| 97 | } /* my_fopen */ |
| 98 |
no test coverage detected