diff --git a/Makefile.common b/Makefile.common index 6a0de66..7e46787 100644 --- a/Makefile.common +++ b/Makefile.common @@ -162,7 +162,6 @@ endif ifneq ($(HAVE_GRIFFIN), 1) SOURCES_CXX += \ - $(MEDNAFEN_DIR)/error.cpp \ $(MEDNAFEN_DIR)/settings.cpp \ $(MEDNAFEN_DIR)/general.cpp \ $(MEDNAFEN_DIR)/FileStream.cpp \ diff --git a/deps/crypto/crypto_types.h b/deps/crypto/crypto_types.h new file mode 100644 index 0000000..697c983 --- /dev/null +++ b/deps/crypto/crypto_types.h @@ -0,0 +1,15 @@ +/********************************************************************* +* Filename: crypto_types.h +* Author: Brad Conte (brad AT bradconte.com) +* Copyright: +* Disclaimer: This code is presented "as is" without any guarantees. +* Details: Defines the API for the corresponding AES implementation. +*********************************************************************/ + +#ifndef CRYPTO_TYPES_H +#define CRYPTO_TYPES_H + +typedef unsigned char BYTE; // 8-bit byte +typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines + +#endif diff --git a/deps/crypto/md5.h b/deps/crypto/md5.h index 1370387..e5b4490 100644 --- a/deps/crypto/md5.h +++ b/deps/crypto/md5.h @@ -11,13 +11,12 @@ /*************************** HEADER FILES ***************************/ #include +#include "crypto_types.h" /****************************** MACROS ******************************/ #define MD5_BLOCK_SIZE 16 // MD5 outputs a 16 byte digest /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines typedef struct { BYTE data[64]; diff --git a/deps/crypto/sha1.h b/deps/crypto/sha1.h index f32bb7c..e4c7869 100644 --- a/deps/crypto/sha1.h +++ b/deps/crypto/sha1.h @@ -12,13 +12,12 @@ /*************************** HEADER FILES ***************************/ #include +#include "crypto_types.h" + /****************************** MACROS ******************************/ #define SHA1_BLOCK_SIZE 20 // SHA1 outputs a 20 byte digest /**************************** DATA TYPES ****************************/ -typedef unsigned char BYTE; // 8-bit byte -typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines - typedef struct { BYTE data[64]; WORD datalen; diff --git a/mednafen/FileStream.cpp b/mednafen/FileStream.cpp index 0722b27..1c428ee 100644 --- a/mednafen/FileStream.cpp +++ b/mednafen/FileStream.cpp @@ -27,16 +27,8 @@ FileStream::FileStream(const char *path, const int mode) { - OpenedMode = mode; - fp = filestream_open(path, (mode == MODE_WRITE) ? RFILE_MODE_WRITE : RFILE_MODE_READ, -1); - - if (!fp) - { - ErrnoHolder ene(errno); - - throw(MDFN_Error(ene.Errno(), "Error opening file %s", ene.StrError())); - } - + OpenedMode = mode; + fp = filestream_open(path, (mode == MODE_WRITE) ? RFILE_MODE_WRITE : RFILE_MODE_READ, -1); original_path = strdup(path); } diff --git a/mednafen/MemoryStream.cpp b/mednafen/MemoryStream.cpp index 6f7d524..36ee7df 100644 --- a/mednafen/MemoryStream.cpp +++ b/mednafen/MemoryStream.cpp @@ -20,8 +20,7 @@ MemoryStream::MemoryStream() : data_buffer(NULL), data_buffer_size(0), data_buff { data_buffer_size = 0; data_buffer_alloced = 64; - if(!(data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced))) - throw MDFN_Error(ErrnoHolder(errno)); + data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced); } MemoryStream::MemoryStream(uint64 size_hint) : data_buffer(NULL), data_buffer_size(0), data_buffer_alloced(0), position(0) @@ -29,8 +28,7 @@ MemoryStream::MemoryStream(uint64 size_hint) : data_buffer(NULL), data_buffer_si data_buffer_size = 0; data_buffer_alloced = (size_hint > SIZE_MAX) ? SIZE_MAX : size_hint; - if(!(data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced))) - throw MDFN_Error(ErrnoHolder(errno)); + data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced); } MemoryStream::MemoryStream(Stream *stream) : data_buffer(NULL), data_buffer_size(0), data_buffer_alloced(0), position(0) @@ -40,8 +38,7 @@ MemoryStream::MemoryStream(Stream *stream) : data_buffer(NULL), data_buffer_size data_buffer_size = stream->size(); data_buffer_alloced = data_buffer_size; - if(!(data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced))) - throw MDFN_Error(ErrnoHolder(errno)); + data_buffer = (uint8*)realloc(data_buffer, data_buffer_alloced); stream->read(data_buffer, data_buffer_size); @@ -53,8 +50,7 @@ MemoryStream::MemoryStream(const MemoryStream &zs) { data_buffer_size = zs.data_buffer_size; data_buffer_alloced = zs.data_buffer_alloced; - if(!(data_buffer = (uint8*)malloc(data_buffer_alloced))) - throw MDFN_Error(ErrnoHolder(errno)); + data_buffer = (uint8*)malloc(data_buffer_alloced); memcpy(data_buffer, zs.data_buffer, data_buffer_size); @@ -101,12 +97,13 @@ INLINE void MemoryStream::grow_if_necessary(uint64 new_required_size) if(new_required_alloced < new_required_size || new_required_alloced > SIZE_MAX) new_required_alloced = SIZE_MAX; +#if 0 // If constrained alloc size isn't enough, throw an out-of-memory/address-space type error. if(new_required_alloced < new_required_size) throw MDFN_Error(ErrnoHolder(ENOMEM)); +#endif - if(!(new_data_buffer = (uint8*)realloc(data_buffer, new_required_alloced))) - throw MDFN_Error(ErrnoHolder(errno)); + new_data_buffer = (uint8*)realloc(data_buffer, new_required_alloced); // // Assign all in one go after the realloc() so we don't leave our object in an inconsistent state if the realloc() fails. @@ -142,8 +139,10 @@ void MemoryStream::write(const void *data, uint64 count) { uint64 nrs = position + count; +#if 0 if(nrs < position) throw MDFN_Error(ErrnoHolder(EFBIG)); +#endif grow_if_necessary(nrs); @@ -157,10 +156,6 @@ void MemoryStream::seek(int64 offset, int whence) switch(whence) { - default: - throw MDFN_Error(ErrnoHolder(EINVAL)); - break; - case SEEK_SET: new_position = offset; break; @@ -174,9 +169,7 @@ void MemoryStream::seek(int64 offset, int whence) break; } - if(new_position < 0) - throw MDFN_Error(ErrnoHolder(EINVAL)); - else + if(!(new_position < 0)) grow_if_necessary(new_position); position = new_position; diff --git a/mednafen/cdrom/CDAccess_CCD.cpp b/mednafen/cdrom/CDAccess_CCD.cpp index 520436f..6395e28 100644 --- a/mednafen/cdrom/CDAccess_CCD.cpp +++ b/mednafen/cdrom/CDAccess_CCD.cpp @@ -52,8 +52,8 @@ static T CCD_ReadInt(CCD_Section &s, const std::string &propname, const bool hav { if(have_defval) return defval; - else - throw MDFN_Error(0, _("Missing property: %s"), propname.c_str()); + printf("Missing property: %s", propname.c_str()); + return 0; } const std::string &v = zit->second; @@ -77,7 +77,8 @@ static T CCD_ReadInt(CCD_Section &s, const std::string &propname, const bool hav if(!vp[0] || ep[0]) { - throw MDFN_Error(0, _("Property %s: Malformed integer: %s"), propname.c_str(), v.c_str()); + printf("Property %s: Malformed integer: %s", propname.c_str(), v.c_str()); + return 0; } return ret; diff --git a/mednafen/cdrom/CDAccess_CHD.cpp b/mednafen/cdrom/CDAccess_CHD.cpp index 0a642b0..1266ada 100644 --- a/mednafen/cdrom/CDAccess_CHD.cpp +++ b/mednafen/cdrom/CDAccess_CHD.cpp @@ -428,10 +428,11 @@ int32_t CDAccess_CHD::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const } } +#if 0 if (!track_found) { - //printf("Could not find track for sector %d\n!", lba); - throw(MDFN_Error(0, _("Could not find track for sector %u!"), lba)); + printf("Could not find track for sector %d\n!", lba); } +#endif if (lba < Tracks[track].LBA) lba_relative = Tracks[track].LBA - 1 - lba; diff --git a/mednafen/cdrom/CDAccess_Image.cpp b/mednafen/cdrom/CDAccess_Image.cpp index 1391c5d..234bf3f 100644 --- a/mednafen/cdrom/CDAccess_Image.cpp +++ b/mednafen/cdrom/CDAccess_Image.cpp @@ -1235,8 +1235,10 @@ int32_t CDAccess_Image::MakeSubPQ(int32_t lba, uint8_t *SubPWBuf) const } } +#if 0 if(!track_found) throw(MDFN_Error(0, _("Could not find track for sector %u!"), lba)); +#endif if(lba < Tracks[track].LBA) lba_relative = Tracks[track].LBA - 1 - lba; diff --git a/mednafen/cdrom/cdromif.cpp b/mednafen/cdrom/cdromif.cpp index 723c016..add964e 100644 --- a/mednafen/cdrom/cdromif.cpp +++ b/mednafen/cdrom/cdromif.cpp @@ -202,7 +202,7 @@ CDIF_ST::CDIF_ST(CDAccess *cda) : disc_cdaccess(cda) if(disc_toc.first_track < 1 || disc_toc.last_track > 99 || disc_toc.first_track > disc_toc.last_track) { - throw(MDFN_Error(0, "TOC first(%d)/last(%d) track numbers bad.", disc_toc.first_track, disc_toc.last_track)); + printf("TOC first(%d)/last(%d) track numbers bad.", disc_toc.first_track, disc_toc.last_track); } } diff --git a/mednafen/error.cpp b/mednafen/error.cpp deleted file mode 100644 index c52d94d..0000000 --- a/mednafen/error.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* Mednafen - Multi-system Emulator - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mednafen.h" -#include "error.h" -#include -#include -#include "../libretro.h" - -extern retro_log_printf_t log_cb; - -MDFN_Error::MDFN_Error() -{ - abort(); -} - -MDFN_Error::MDFN_Error(int errno_code_new, const char *format, ...) -{ - errno_code = errno_code_new; - - va_list ap; - va_start(ap, format); - vsnprintf(error_message, 4096, format, ap); - va_end(ap); - - if (log_cb) - log_cb(RETRO_LOG_ERROR, "%s\n", error_message); -} - - -MDFN_Error::MDFN_Error(const ErrnoHolder &enh) -{ - errno_code = enh.Errno(); - - error_message = strdup(enh.StrError()); -} - - -MDFN_Error::~MDFN_Error() -{ - if(error_message) - { - free(error_message); - error_message = NULL; - } -} - -MDFN_Error::MDFN_Error(const MDFN_Error &ze_error) -{ - if(ze_error.error_message) - error_message = strdup(ze_error.error_message); - else - error_message = NULL; - - errno_code = ze_error.errno_code; -} - -MDFN_Error& MDFN_Error::operator=(const MDFN_Error &ze_error) -{ - char *new_error_message = ze_error.error_message ? strdup(ze_error.error_message) : NULL; - int new_errno_code = ze_error.errno_code; - - if(error_message) - free(error_message); - - error_message = new_error_message; - errno_code = new_errno_code; - - return(*this); -} - - -const char * MDFN_Error::what(void) -{ - if(!error_message) - return("Error allocating memory for the error message!"); - - return(error_message); -} - -int MDFN_Error::GetErrno(void) -{ - return(errno_code); -} - -static const char *srr_wrap(int ret, const char *local_strerror) -{ - if(ret == -1) - return("ERROR IN strerror_r()!!!"); - - return(local_strerror); -} - -static const char *srr_wrap(const char *ret, const char *local_strerror) -{ - if(ret == NULL) - return("ERROR IN strerror_r()!!!"); - - return(ret); -} - -void ErrnoHolder::SetErrno(int the_errno) -{ - local_errno = the_errno; - - if(the_errno == 0) - local_strerror[0] = 0; - else - { - strncpy(local_strerror, strerror(the_errno), 255); - - local_strerror[255] = 0; - } -} - diff --git a/mednafen/error.h b/mednafen/error.h deleted file mode 100644 index 5ad6067..0000000 --- a/mednafen/error.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef __MDFN_ERROR_H -#define __MDFN_ERROR_H - -#include -#include - -#ifdef __cplusplus - -class ErrnoHolder; -class MDFN_Error -{ - public: - - MDFN_Error(); - - MDFN_Error(int errno_code_new, const char *format, ...); - MDFN_Error(const ErrnoHolder &enh); - - ~MDFN_Error(); - - MDFN_Error(const MDFN_Error &ze_error); - MDFN_Error & operator=(const MDFN_Error &ze_error); - - virtual const char *what(void); - int GetErrno(void); - - private: - - int errno_code; - char *error_message; -}; - -class ErrnoHolder -{ - public: - - ErrnoHolder() - { - local_errno = 0; - local_strerror[0] = 0; - } - - ErrnoHolder(int the_errno) - { - SetErrno(the_errno); - } - - inline int Errno(void) const - { - return(local_errno); - } - - const char *StrError(void) const - { - return(local_strerror); - } - - void operator=(int the_errno) - { - SetErrno(the_errno); - } - - private: - - void SetErrno(int the_errno); - - int local_errno; - char local_strerror[256]; -}; - -#endif - -#endif diff --git a/mednafen/general.cpp b/mednafen/general.cpp index 9aec7e1..07f5581 100644 --- a/mednafen/general.cpp +++ b/mednafen/general.cpp @@ -125,20 +125,15 @@ void MDFN_GetFilePathComponents(const std::string &file_path, std::string MDFN_EvalFIP(const std::string &dir_path, const std::string &rel_path, bool skip_safety_check) { - char slash; #ifdef _WIN32 - slash = '\\'; + char slash = '\\'; #else - slash = '/'; + char slash = '/'; #endif - if(!skip_safety_check && !MDFN_IsFIROPSafe(rel_path)) - throw MDFN_Error(0, _("Referenced path \"%s\" is potentially unsafe. See \"filesys.untrusted_fip_check\" setting.\n"), rel_path.c_str()); - if(IsAbsolutePath(rel_path.c_str())) return(rel_path); - else - return(dir_path + slash + rel_path); + return(dir_path + slash + rel_path); } // Remove whitespace from beginning of string diff --git a/mednafen/mednafen-endian.h b/mednafen/mednafen-endian.h index 353abb3..96a8539 100644 --- a/mednafen/mednafen-endian.h +++ b/mednafen/mednafen-endian.h @@ -3,7 +3,6 @@ #include #include -#include #ifdef __cplusplus extern "C" { diff --git a/mednafen/mednafen-types.h b/mednafen/mednafen-types.h index c2deac5..f0a4fb8 100644 --- a/mednafen/mednafen-types.h +++ b/mednafen/mednafen-types.h @@ -118,7 +118,4 @@ typedef unsigned char Boolean; /* 0 or 1 */ #undef require #define require( expr ) assert( expr ) -#include "error.h" - - #endif diff --git a/mednafen/mednafen.h b/mednafen/mednafen.h index a429196..c702a10 100644 --- a/mednafen/mednafen.h +++ b/mednafen/mednafen.h @@ -21,11 +21,6 @@ #define GET_FDATA_PTR(fp) (fp->data) #define GET_FSIZE_PTR(fp) (fp->size) #define GET_FEXTS_PTR(fp) (fp->ext) -#define gzopen(a, b) fopen(a, b) -#define gzread(a, b, c) fread(b, c, 1, a) -#define gzclose(a) fclose(a) -#define gzgetc(a) fgetc(a) -#define gzseek(a,b,c) fseek(a,b,c) extern MDFNGI *MDFNGameInfo;