diff --git a/Makefile b/Makefile index 442a0d3181..f07ab3454c 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ include config.mk TARGET = ssnes tools/ssnes-joyconfig -OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o patch.o compat/strl.o compat/getopt.o screenshot.o audio/utils.o -JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o compat/strl.o +OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o patch.o compat/compat.o screenshot.o audio/utils.o +JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o compat/compat.o HEADERS = $(wildcard */*.h) $(wildcard *.h) LIBS = -lm diff --git a/Makefile.win b/Makefile.win index c5043ca6db..d6aaf19a4e 100644 --- a/Makefile.win +++ b/Makefile.win @@ -1,7 +1,7 @@ TARGET = ssnes.exe JTARGET = ssnes-joyconfig.exe -OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o patch.o compat/strl.o screenshot.o compat/getopt.o audio/utils.o compat/posix_string.o -JOBJ = conf/config_file.o tools/ssnes-joyconfig.o compat/strl.o compat/posix_string.o +OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o patch.o compat/compat.o screenshot.o audio/utils.o +JOBJ = conf/config_file.o tools/ssnes-joyconfig.o compat/compat.o CC = gcc CXX = g++ diff --git a/compat/getopt.c b/compat/compat.c similarity index 78% rename from compat/getopt.c rename to compat/compat.c index f189baee39..4063d10e6c 100644 --- a/compat/getopt.c +++ b/compat/compat.c @@ -16,6 +16,8 @@ */ #include "getopt_ssnes.h" +#include "strl.h" +#include "posix_string.h" #ifndef HAVE_GETOPT_LONG @@ -196,3 +198,85 @@ int getopt_long(int argc, char *argv[], #endif +#ifndef HAVE_STRL + +// Implementation of strlcpy()/strlcat() based on OpenBSD. + +size_t strlcpy(char *dest, const char *source, size_t size) +{ + size_t src_size = 0; + size_t n = size; + + if (n) + while (--n && (*dest++ = *source++)) src_size++; + + if (!n) + { + if (size) *dest = '\0'; + while (*source++) src_size++; + } + + return src_size; +} + +size_t strlcat(char *dest, const char *source, size_t size) +{ + size_t len = strlen(dest); + dest += len; + + if (len > size) + size = 0; + else + size -= len; + + return len + strlcpy(dest, source, size); +} + +#endif + +#ifdef _WIN32 + +#undef strcasecmp +#undef strdup +#undef isblank +#include +#include +#include +#include "strl.h" + +#include + +int strcasecmp_ssnes__(const char *a, const char *b) +{ + while (*a && *b) + { + int a_ = tolower(*a); + int b_ = tolower(*b); + if (a_ != b_) + return a_ - b_; + + a++; + b++; + } + + return tolower(*a) - tolower(*b); +} + +char *strdup_ssnes__(const char *orig) +{ + size_t len = strlen(orig) + 1; + char *ret = (char*)malloc(len); + if (!ret) + return NULL; + + strlcpy(ret, orig, len); + return ret; +} + +int isblank_ssnes__(int c) +{ + return (c == ' ') || (c == '\t'); +} + +#endif + diff --git a/compat/posix_string.c b/compat/posix_string.c deleted file mode 100644 index fb8497121c..0000000000 --- a/compat/posix_string.c +++ /dev/null @@ -1,61 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * - * Some code herein may be based on code found in BSNES. - * - * SSNES 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 Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES 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 SSNES. - * If not, see . - */ - -#include "posix_string.h" - -#undef strcasecmp -#undef strdup -#undef isblank -#include -#include -#include -#include "strl.h" - -#include - -int strcasecmp_ssnes__(const char *a, const char *b) -{ - while (*a && *b) - { - int a_ = tolower(*a); - int b_ = tolower(*b); - if (a_ != b_) - return a_ - b_; - - a++; - b++; - } - - return tolower(*a) - tolower(*b); -} - -char *strdup_ssnes__(const char *orig) -{ - size_t len = strlen(orig) + 1; - char *ret = (char*)malloc(len); - if (!ret) - return NULL; - - strlcpy(ret, orig, len); - return ret; -} - -int isblank_ssnes__(int c) -{ - return (c == ' ') || (c == '\t'); -} - diff --git a/compat/strl.c b/compat/strl.c deleted file mode 100644 index 31f7fd3171..0000000000 --- a/compat/strl.c +++ /dev/null @@ -1,52 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * - * Some code herein may be based on code found in BSNES. - * - * SSNES 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 Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES 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 SSNES. - * If not, see . - */ - -#include "strl.h" - -#ifndef HAVE_STRL -// Implementation of strlcpy()/strlcat() based on OpenBSD. - -size_t strlcpy(char *dest, const char *source, size_t size) -{ - size_t src_size = 0; - size_t n = size; - - if (n) - while (--n && (*dest++ = *source++)) src_size++; - - if (!n) - { - if (size) *dest = '\0'; - while (*source++) src_size++; - } - - return src_size; -} - -size_t strlcat(char *dest, const char *source, size_t size) -{ - size_t len = strlen(dest); - dest += len; - - if (len > size) - size = 0; - else - size -= len; - - return len + strlcpy(dest, source, size); -} -#endif