Fix BSD build. Convert strcpy()/strcat() to strl* variants.

This commit is contained in:
Themaister 2011-06-16 22:47:37 +02:00
parent 45904ccd73
commit 753d2057bb
5 changed files with 31 additions and 24 deletions

View File

@ -16,6 +16,13 @@ else
OSX := 0 OSX := 0
endif 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) ifeq ($(HAVE_SRC), 1)
LIBS += $(SRC_LIBS) LIBS += $(SRC_LIBS)
DEFINES += $(SRC_CFLAGS) DEFINES += $(SRC_CFLAGS)
@ -68,7 +75,7 @@ endif
ifeq ($(HAVE_SDL), 1) ifeq ($(HAVE_SDL), 1)
OBJ += gfx/sdl.o gfx/gl.o input/sdl.o audio/sdl.o fifo_buffer.o 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) LIBS += $(SDL_LIBS)
ifeq ($(OSX),1) ifeq ($(OSX),1)
LIBS += -framework OpenGL LIBS += -framework OpenGL
@ -95,7 +102,7 @@ endif
ifeq ($(HAVE_DYLIB), 1) ifeq ($(HAVE_DYLIB), 1)
OBJ += gfx/ext.o audio/ext.o OBJ += gfx/ext.o audio/ext.o
LIBS += -ldl LIBS += $(DYLIB_LIB)
endif endif
ifeq ($(HAVE_FREETYPE), 1) ifeq ($(HAVE_FREETYPE), 1)
@ -116,7 +123,7 @@ ifeq ($(HAVE_FFMPEG), 1)
endif endif
ifeq ($(HAVE_DYNAMIC), 1) ifeq ($(HAVE_DYNAMIC), 1)
LIBS += -ldl LIBS += $(DYLIB_LIB)
else else
LIBS += $(libsnes) LIBS += $(libsnes)
endif endif

12
file.c
View File

@ -572,15 +572,9 @@ char** dir_list_new(const char *dir, const char *ext)
if (!dir_list[cur_ptr]) if (!dir_list[cur_ptr])
goto error; goto error;
strcpy(dir_list[cur_ptr], dir); strlcpy(dir_list[cur_ptr], dir, final_off);
#ifdef _WIN32 strlcat(dir_list[cur_ptr], "/", final_off);
dir_list[cur_ptr][path_len] = '\\'; strlcat(dir_list[cur_ptr], entry->d_name, final_off);
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';
cur_ptr++; cur_ptr++;
if (cur_ptr + 1 == cur_size) // Need to reserve for NULL. if (cur_ptr + 1 == cur_size) // Need to reserve for NULL.

View File

@ -3,6 +3,12 @@
check_switch_c C99 -std=gnu99 check_switch_c C99 -std=gnu99
check_critical C99 "Cannot find C99 compatible compiler." 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 if [ "$HAVE_DYNAMIC" = "yes" ] && [ "$HAVE_CONFIGFILE" = "no" ]; then
echo "Cannot have dynamic loading of libsnes and no configfile support." echo "Cannot have dynamic loading of libsnes and no configfile support."
echo "Dynamic loading requires config file support." echo "Dynamic loading requires config file support."
@ -10,12 +16,12 @@ if [ "$HAVE_DYNAMIC" = "yes" ] && [ "$HAVE_CONFIGFILE" = "no" ]; then
fi fi
if [ $HAVE_DYNAMIC != yes ]; then 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." check_critical SNES "Cannot find libsnes."
add_define_make libsnes $LIBSNES add_define_make libsnes $LIBSNES
fi fi
check_lib DYLIB -ldl dlopen check_lib DYLIB $DYLIB dlopen
check_lib NETPLAY -lc socket check_lib NETPLAY -lc socket
check_lib ALSA -lasound snd_pcm_open check_lib ALSA -lasound snd_pcm_open
@ -56,7 +62,7 @@ fi
check_pkgconf SRC samplerate check_pkgconf SRC samplerate
check_lib DYNAMIC -ldl dlopen check_lib DYNAMIC $DYLIB dlopen
check_pkgconf FREETYPE freetype2 check_pkgconf FREETYPE freetype2
check_lib XVIDEO -lXv XvShmCreateImage check_lib XVIDEO -lXv XvShmCreateImage

View File

@ -194,8 +194,8 @@ static config_file_t *open_default_config_file(void)
if (appdata) if (appdata)
{ {
char conf_path[strlen(appdata) + strlen("/ssnes.cfg ")]; char conf_path[strlen(appdata) + strlen("/ssnes.cfg ")];
strcpy(conf_path, appdata); strlcpy(conf_path, appdata, sizeof(conf_path));
strcat(conf_path, "/ssnes.cfg"); strlcat(conf_path, "/ssnes.cfg", sizeof(conf_path));
conf = config_file_new(conf_path); conf = config_file_new(conf_path);
} }
} }
@ -204,8 +204,8 @@ static config_file_t *open_default_config_file(void)
if (home) if (home)
{ {
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")]; char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
strcpy(conf_path, home); strlcpy(conf_path, home, sizeof(conf_path));
strcat(conf_path, "/.ssnes.cfg"); strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path));
conf = config_file_new(conf_path); conf = config_file_new(conf_path);
} }
if (!conf) if (!conf)
@ -219,15 +219,15 @@ static config_file_t *open_default_config_file(void)
if (xdg) if (xdg)
{ {
char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")]; char conf_path[strlen(xdg) + strlen("/ssnes/ssnes.cfg ")];
strcpy(conf_path, xdg); strlcpy(conf_path, xdg, sizeof(conf_path));
strcat(conf_path, "/ssnes/ssnes.cfg"); strlcat(conf_path, "/ssnes/ssnes.cfg", sizeof(conf_path));
conf = config_file_new(conf_path); conf = config_file_new(conf_path);
} }
else if (home) else if (home)
{ {
char conf_path[strlen(home) + strlen("/.ssnes.cfg ")]; char conf_path[strlen(home) + strlen("/.ssnes.cfg ")];
strcpy(conf_path, home); strlcpy(conf_path, home, sizeof(conf_path));
strcat(conf_path, "/.ssnes.cfg"); strlcat(conf_path, "/.ssnes.cfg", sizeof(conf_path));
conf = config_file_new(conf_path); conf = config_file_new(conf_path);
} }
// Try this as a last chance... // Try this as a last chance...

View File

@ -418,7 +418,7 @@ static void print_help(void)
static void set_basename(const char *path) static void set_basename(const char *path)
{ {
char tmp[strlen(path) + 1]; char tmp[strlen(path) + 1];
strcpy(tmp, path); strlcpy(tmp, path, sizeof(tmp));
char *dst = strrchr(tmp, '.'); char *dst = strrchr(tmp, '.');
if (dst) if (dst)
*dst = '\0'; *dst = '\0';