Skip to content

Commit

Permalink
CHG: more consequent use of dr_fopen()
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11412 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Oct 2, 2024
1 parent 39fe94e commit 37193ef
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/simutrans/dataobj/pakset_downloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool pak_need_update(const paksetinfo_t *pi)
outside.append(PATH_SEPARATOR);
outside.append("ground.Outside.pak");

if( FILE* f = fopen(outside.get_str(), "r") ) {
if( FILE* f = dr_fopen(outside.get_str(), "r") ) {
fseek(f, 99, SEEK_SET);
uint8 len = fgetc(f);
fgetc(f);
Expand Down Expand Up @@ -378,14 +378,14 @@ static size_t curl_write_data(void* ptr, size_t size, size_t nmemb, FILE* stream

static CURLcode curl_download_file(CURL* curl, const char* target_file, const char* url)
{
FILE* fp = fopen(target_file, "wb");
FILE* fp = dr_fopen(target_file, "wb");
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
char cabundle_path[PATH_MAX];
sprintf(cabundle_path, "%s%s", env_t::base_dir, "cacert.pem");
FILE* cabundle_file;
if ((cabundle_file = fopen(cabundle_path, "r"))) {
if ((cabundle_file = dr_fopen(cabundle_path, "r"))) {
fclose(cabundle_file);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_CAINFO, cabundle_path);
Expand Down
2 changes: 1 addition & 1 deletion src/simutrans/dataobj/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ void settings_t::parse_simuconf( tabfile_t& simuconf, sint16& disp_width, sint16
// check for fontname, must be a valid name!
// will be only changed if default!
std::string fname = trim( contents.get_string( "fontname", env_t::fontname.c_str() ) );
if( FILE* f = fopen( fname.c_str(), "r" ) ) {
if( FILE* f = dr_fopen( fname.c_str(), "r" ) ) {
fclose( f );
env_t::fontname = fname;
}
Expand Down
2 changes: 1 addition & 1 deletion src/simutrans/gui/loadfont_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool loadfont_frame_t::compare_items ( const dir_entry_t & entry, const char *in
*/
bool loadfont_frame_t::check_file(const char *filename, const char *)
{
FILE *test = fopen( filename, "r" );
FILE *test = dr_fopen( filename, "r" );
if( test == NULL ) {
return false;
}
Expand Down
15 changes: 5 additions & 10 deletions src/simutrans/io/classify_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

#include <cstring>

#ifdef MAKEOBJ
#define dr_fopen fopen
#endif



bool classify_as_png(FILE *f, file_info_t *info);
bool classify_as_bmp(FILE *f, file_info_t *info);
Expand Down Expand Up @@ -61,12 +66,7 @@ file_classify_status_t classify_save_file(const char *path, file_info_t *info)
return FILE_CLASSIFY_INVALID_ARGS;
}

#ifdef MAKEOBJ
FILE *f = fopen(path, "rb");
#else
FILE *f = dr_fopen(path, "rb");
#endif

if (!f) {
// Do not warn about this since we can also use this function to check whether a file exists
return FILE_CLASSIFY_NOT_EXISTING;
Expand Down Expand Up @@ -150,12 +150,7 @@ file_classify_status_t classify_image_file(const char *path, file_info_t *info)
return FILE_CLASSIFY_INVALID_ARGS;
}

#ifdef MAKEOBJ
FILE *f = fopen(path, "rb");
#else
FILE *f = dr_fopen(path, "rb");
#endif

if (!f) {
// Do not warn about this since we can also use this function to check whether a file exists
return FILE_CLASSIFY_NOT_EXISTING;
Expand Down
11 changes: 4 additions & 7 deletions src/simutrans/io/raw_image_bmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#define BMPINFOHEADER_OFFSET (14)

#ifdef MAKEOBJ
#define dr_fopen fopen
#endif

#ifdef _MSC_VER
#pragma pack(push, 1)
Expand Down Expand Up @@ -76,12 +79,7 @@ static bool is_format_supported(uint16 bpp, uint32 compression)

bool raw_image_t::read_bmp(const char *filename)
{
#ifdef MAKEOBJ
FILE *file = fopen(filename, "rb");
#else
FILE *file = dr_fopen(filename, "rb");
#endif

bitmap_file_header_t bmp_header;

if (fread(&bmp_header, sizeof(bitmap_file_header_t), 1, file) != 1) {
Expand Down Expand Up @@ -395,8 +393,7 @@ bool raw_image_t::write_bmp(const char *filename) const
fheader.file_size = endian(uint32(headers_size + gap1_size + image_data_size));

// now actually write the data
FILE *f = fopen(filename, "wb");

FILE *f = dr_fopen(filename, "wb");
if (!f) {
return false;
}
Expand Down
10 changes: 7 additions & 3 deletions src/simutrans/io/raw_image_png.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "../simmem.h"
#include "../simdebug.h"

#ifdef MAKEOBJ
#define dr_fopen fopen
#else
#include "../sys/simsys.h"
#endif

static std::string filename_;

Expand Down Expand Up @@ -167,8 +172,7 @@ bool raw_image_t::read_png(const char *fname)
// remember the file name for better error messages.
filename_ = fname;

FILE* file = fopen(fname, "rb");

FILE* file = dr_fopen(fname, "rb");
if (file) {
const bool ok = read_png_data(file);
fclose(file);
Expand All @@ -188,7 +192,7 @@ bool raw_image_t::write_png(const char *file_name) const

png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
FILE *fp = fopen(file_name, "wb");
FILE *fp = dr_fopen(file_name, "wb");
if (!fp) {
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions src/simutrans/io/raw_image_ppm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#include "../simio.h"
#include "../simmem.h"

#ifdef MAKEOBJ
#define dr_fopen fopen
#else
#include "../sys/simsys.h"
#endif

bool raw_image_t::read_ppm(const char *filename)
{
#ifdef MAKEOBJ
FILE *file = fopen(filename, "rb");
#else
FILE *file = dr_fopen(filename, "rb");
#endif

// ppm format
char buf[255];
Expand Down
2 changes: 1 addition & 1 deletion src/simutrans/sys/simsys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ bool dr_set_basedir(const char * base_dir_arg, char * executable_path)
dr_getcwd(env_t::base_dir, lengthof(env_t::base_dir));
strcat( env_t::base_dir, PATH_SEPARATOR );
// test if base installation
if (FILE* f = fopen("config/simuconf.tab", "r")) {
if (FILE* f = dr_fopen("config/simuconf.tab", "r")) {
fclose(f);
found_basedir = true;
}
Expand Down

0 comments on commit 37193ef

Please sign in to comment.