| 124 | static const char* const FOPEN_READ_ONLY = "rb"; |
| 125 | |
| 126 | FILE* ext_fopen(Database* dbb, ExternalFile* ext_file) |
| 127 | { |
| 128 | const char* file_name = ext_file->ext_filename; |
| 129 | |
| 130 | ExternalFileDirectoryList::create(dbb); |
| 131 | if (!dbb->dbb_external_file_directory_list->isPathInList(file_name)) |
| 132 | { |
| 133 | ERR_post(Arg::Gds(isc_conf_access_denied) << Arg::Str("external file") << |
| 134 | Arg::Str(file_name)); |
| 135 | } |
| 136 | |
| 137 | // If the database is updateable, then try opening the external files in |
| 138 | // RW mode. If the DB is ReadOnly, then open the external files only in |
| 139 | // ReadOnly mode, thus being consistent. |
| 140 | if (!dbb->readOnly()) |
| 141 | ext_file->ext_ifi = os_utils::fopen(file_name, FOPEN_TYPE); |
| 142 | |
| 143 | if (!ext_file->ext_ifi) |
| 144 | { |
| 145 | // could not open the file as read write attempt as read only |
| 146 | if (!(ext_file->ext_ifi = os_utils::fopen(file_name, FOPEN_READ_ONLY))) |
| 147 | { |
| 148 | ERR_post(Arg::Gds(isc_io_error) << Arg::Str("fopen") << Arg::Str(file_name) << |
| 149 | Arg::Gds(isc_io_open_err) << SYS_ERR(errno)); |
| 150 | } |
| 151 | else { |
| 152 | ext_file->ext_flags |= EXT_readonly; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return ext_file->ext_ifi; |
| 157 | } |
| 158 | } // namespace |
| 159 | |
| 160 | |