From eb085a8068e6ec02ee747c731ce1d98176f4367c Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 16 Jun 2011 22:47:37 +0200 Subject: [PATCH 1/2] Fix BSD build. Convert strcpy()/strcat() to strl* variants. --- Makefile | 13 ++++++++++--- file.c | 12 +++--------- qb/config.libs.sh | 12 +++++++++--- settings.c | 16 ++++++++-------- ssnes.c | 2 +- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 2a4bfa3954..35a282c9a7 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,13 @@ else OSX := 0 endif +BSD_LOCAL_INC = +DYLIB_LIB = -ldl +ifneq ($(findstring BSD,$(shell uname -a)),) + BSD_LOCAL_INC = -I/usr/local/include + DYLIB_LIB = -lc +endif + ifeq ($(HAVE_SRC), 1) LIBS += $(SRC_LIBS) DEFINES += $(SRC_CFLAGS) @@ -68,7 +75,7 @@ endif ifeq ($(HAVE_SDL), 1) OBJ += gfx/sdl.o gfx/gl.o input/sdl.o audio/sdl.o fifo_buffer.o - DEFINES += $(SDL_CFLAGS) + DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC) LIBS += $(SDL_LIBS) ifeq ($(OSX),1) LIBS += -framework OpenGL @@ -95,7 +102,7 @@ endif ifeq ($(HAVE_DYLIB), 1) OBJ += gfx/ext.o audio/ext.o - LIBS += -ldl + LIBS += $(DYLIB_LIB) endif ifeq ($(HAVE_FREETYPE), 1) @@ -116,7 +123,7 @@ ifeq ($(HAVE_FFMPEG), 1) endif ifeq ($(HAVE_DYNAMIC), 1) - LIBS += -ldl + LIBS += $(DYLIB_LIB) else LIBS += $(libsnes) endif diff --git a/file.c b/file.c index 157780e751..2c100075c3 100644 --- a/file.c +++ b/file.c @@ -572,15 +572,9 @@ char** dir_list_new(const char *dir, const char *ext) if (!dir_list[cur_ptr]) goto error; - strcpy(dir_list[cur_ptr], dir); -#ifdef _WIN32 - dir_list[cur_ptr][path_len] = '\\'; - strcpy(&dir_list[cur_ptr][path_len + 1], utf8_buf); -#else - dir_list[cur_ptr][path_len] = '/'; - strcpy(&dir_list[cur_ptr][path_len + 1], entry->d_name); -#endif - dir_list[cur_ptr][final_off - 1] = '\0'; + strlcpy(dir_list[cur_ptr], dir, final_off); + strlcat(dir_list[cur_ptr], "/", final_off); + strlcat(dir_list[cur_ptr], entry->d_name, final_off); cur_ptr++; if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. diff --git a/qb/config.libs.sh b/qb/config.libs.sh index a6167e7cf6..04410b9e6f 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -3,6 +3,12 @@ check_switch_c C99 -std=gnu99 check_critical C99 "Cannot find C99 compatible compiler." +if [ "$OS" = BSD ]; then + DYLIB=-lc +else + DYLIB=-ldl +fi + if [ "$HAVE_DYNAMIC" = "yes" ] && [ "$HAVE_CONFIGFILE" = "no" ]; then echo "Cannot have dynamic loading of libsnes and no configfile support." echo "Dynamic loading requires config file support." @@ -10,12 +16,12 @@ if [ "$HAVE_DYNAMIC" = "yes" ] && [ "$HAVE_CONFIGFILE" = "no" ]; then fi if [ $HAVE_DYNAMIC != yes ]; then - check_lib_cxx SNES $LIBSNES snes_init -ldl + check_lib_cxx SNES $LIBSNES snes_init $DYLIB check_critical SNES "Cannot find libsnes." add_define_make libsnes $LIBSNES fi -check_lib DYLIB -ldl dlopen +check_lib DYLIB $DYLIB dlopen check_lib NETPLAY -lc socket check_lib ALSA -lasound snd_pcm_open @@ -56,7 +62,7 @@ fi check_pkgconf SRC samplerate -check_lib DYNAMIC -ldl dlopen +check_lib DYNAMIC $DYLIB dlopen check_pkgconf FREETYPE freetype2 check_lib XVIDEO -lXv XvShmCreateImage diff --git a/settings.c b/settings.c index 1d62d0316c..3c5411cadf 100644 --- a/settings.c +++ b/settings.c @@ -194,8 +194,8 @@ static config_file_t *open_default_config_file(void) if (appdata) { char conf_path[strlen(appdata) + strlen("/ssnes.cfg ")]; - strcpy(conf_path, appdata); - strcat(conf_path, "/ssnes.cfg"); + strlcpy(conf_path, appdata, sizeof(conf_path)); + strlcat(conf_path, "/ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); } } @@ -204,8 +204,8 @@ static config_file_t *open_default_config_file(void) if (home) { char conf_path[strlen(home) + strlen("/.ssnes.cfg ")]; - strcpy(conf_path, home); - strcat(conf_path, "/.ssnes.cfg"); + strlcpy(conf_path, home, sizeof(conf_path)); + strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); } if (!conf) @@ -219,15 +219,15 @@ static config_file_t *open_default_config_file(void) if (xdg) { char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")]; - strcpy(conf_path, xdg); - strcat(conf_path, "/ssnes/ssnes.cfg"); + strlcpy(conf_path, xdg, sizeof(conf_path)); + strlcat(conf_path, "/ssnes/ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); } else if (home) { char conf_path[strlen(home) + strlen("/.ssnes.cfg ")]; - strcpy(conf_path, home); - strcat(conf_path, "/.ssnes.cfg"); + strlcpy(conf_path, home, sizeof(conf_path)); + strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path)); conf = config_file_new(conf_path); } // Try this as a last chance... diff --git a/ssnes.c b/ssnes.c index 799fced310..79fde88912 100644 --- a/ssnes.c +++ b/ssnes.c @@ -418,7 +418,7 @@ static void print_help(void) static void set_basename(const char *path) { char tmp[strlen(path) + 1]; - strcpy(tmp, path); + strlcpy(tmp, path, sizeof(tmp)); char *dst = strrchr(tmp, '.'); if (dst) *dst = '\0'; From b06d814d9c0459e385341812af2c42b43fa26c4a Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 16 Jun 2011 23:20:12 +0200 Subject: [PATCH 2/2] Fix OSS build for BSD. --- Makefile | 4 ++++ audio/oss.c | 42 ++++++++++++++++++++++++++---------------- config.features.h | 2 +- driver.c | 2 +- qb/config.libs.sh | 8 +++++++- qb/qb.libs.sh | 19 ++++++++++++++----- 6 files changed, 53 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 35a282c9a7..6a1967aace 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,10 @@ endif ifeq ($(HAVE_OSS), 1) OBJ += audio/oss.o endif +ifeq ($(HAVE_OSS_BSD), 1) + OBJ += audio/oss.o + LIBS += -lossaudio +endif ifeq ($(HAVE_ALSA), 1) OBJ += audio/alsa.o LIBS += -lasound diff --git a/audio/oss.c b/audio/oss.c index e794d6a9ef..272de6405e 100644 --- a/audio/oss.c +++ b/audio/oss.c @@ -15,28 +15,43 @@ * If not, see . */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "driver.h" #include + +#ifdef HAVE_OSS_BSD +#include +#else #include +#endif + #include #include #include #include #include +#ifdef HAVE_OSS_BSD +#define DEFAULT_OSS_DEV "/dev/audio" +#else +#define DEFAULT_OSS_DEV "/dev/dsp" +#endif + static void* __oss_init(const char* device, unsigned rate, unsigned latency) { int *fd = calloc(1, sizeof(int)); - if ( fd == NULL ) + if (fd == NULL) return NULL; - const char *oss_device = "/dev/dsp"; + const char *oss_device = DEFAULT_OSS_DEV; - if ( device != NULL ) + if (device != NULL) oss_device = device; - if ( (*fd = open(oss_device, O_WRONLY)) < 0 ) + if ((*fd = open(oss_device, O_WRONLY)) < 0) { free(fd); return NULL; @@ -45,7 +60,7 @@ static void* __oss_init(const char* device, unsigned rate, unsigned latency) int frags = (latency * rate * 4)/(1000 * (1 << 9)); int frag = (frags << 16) | 9; - if ( ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0 ) + if (ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0) { close(*fd); free(fd); @@ -55,21 +70,21 @@ static void* __oss_init(const char* device, unsigned rate, unsigned latency) int channels = 2; int format = AFMT_S16_LE; - if ( ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0 ) + if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0) { close(*fd); free(fd); return NULL; } - if ( ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0 ) + if (ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0) { close(*fd); free(fd); return NULL; } - if ( ioctl(*fd, SNDCTL_DSP_SPEED, &rate) < 0 ) + if (ioctl(*fd, SNDCTL_DSP_SPEED, &rate) < 0) { close(*fd); free(fd); @@ -83,13 +98,13 @@ static ssize_t __oss_write(void* data, const void* buf, size_t size) { int *fd = data; - if ( size == 0 ) + if (size == 0) return 0; ssize_t ret; - if ( (ret = write(*fd, buf, size)) <= 0 ) + if ((ret = write(*fd, buf, size)) <= 0) { - if ( (fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN ) + if ((fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN) return 0; return -1; } @@ -139,9 +154,4 @@ const audio_driver_t audio_oss = { .free = __oss_free, .ident = "oss" }; - - - - - diff --git a/config.features.h b/config.features.h index d1a8d2d209..6ee4111eef 100644 --- a/config.features.h +++ b/config.features.h @@ -20,7 +20,7 @@ static const bool _alsa_supp = true; static const bool _alsa_supp = false; #endif -#ifdef HAVE_OSS +#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD) static const bool _oss_supp = true; #else static const bool _oss_supp = false; diff --git a/driver.c b/driver.c index 4cc7518173..89cbaedc3b 100644 --- a/driver.c +++ b/driver.c @@ -32,7 +32,7 @@ static const audio_driver_t *audio_drivers[] = { #ifdef HAVE_ALSA &audio_alsa, #endif -#ifdef HAVE_OSS +#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD) &audio_oss, #endif #ifdef HAVE_RSOUND diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 04410b9e6f..f78ad11852 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -26,6 +26,12 @@ check_lib NETPLAY -lc socket check_lib ALSA -lasound snd_pcm_open check_header OSS sys/soundcard.h +check_header OSS_BSD soundcard.h +check_lib OSS_LIB -lossaudio + +if [ "$HAVE_OSS_BSD" = "yes" ]; then + check_critical OSS_LIB "Have BSD-style OSS, but -lossaudio is not present." +fi if [ "$OS" = "Darwin" ]; then check_lib AL "-framework OpenAL" alcOpenDevice @@ -72,7 +78,7 @@ check_lib STRL -lc strlcpy check_pkgconf PYTHON python3 # Creates config.mk and config.h. -VARS="ALSA OSS AL RSOUND ROAR JACK PULSE SDL DYLIB CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL PYTHON" +VARS="ALSA OSS OSS_BSD AL RSOUND ROAR JACK PULSE SDL DYLIB CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE SRC CONFIGFILE FREETYPE XVIDEO NETPLAY FBO STRL PYTHON" create_config_make config.mk $VARS create_config_header config.h $VARS diff --git a/qb/qb.libs.sh b/qb/qb.libs.sh index 36b6f5b689..131d8314db 100644 --- a/qb/qb.libs.sh +++ b/qb/qb.libs.sh @@ -41,9 +41,13 @@ check_lib() eval tmpval=\$$tmpval [ "$tmpval" = "no" ] && return 0 - echo -n "Checking function $3 in $2 ... " - echo "void $3(void); int main(void) { $3(); return 0; }" > $TEMP_C - + if [ -z "$3" ]; then + echo -n "Checking existence of $2 ..." + echo "int main(void) { return 0; }" > $TEMP_C + else + echo -n "Checking function $3 in $2 ... " + echo "void $3(void); int main(void) { $3(); return 0; }" > $TEMP_C + fi eval HAVE_$1=no answer=no @@ -67,8 +71,13 @@ check_lib_cxx() eval tmpval=\$$tmpval [ "$tmpval" = "no" ] && return 0 - echo -n "Checking function $3 in $2 ... " - echo "extern \"C\" { void $3(void); } int main() { $3(); }" > $TEMP_CXX + if [ -z "$3" ]; then + echo -n "Checking existence of $2 ..." + echo "int main(void) { return 0; }" > $TEMP_C + else + echo -n "Checking function $3 in $2 ... " + echo "extern \"C\" { void $3(void); } int main() { $3(); }" > $TEMP_CXX + fi eval HAVE_$1=no answer=no