Turn these into inline functions for sanity.

This commit is contained in:
Brandon Wright 2018-11-18 11:33:18 -06:00
parent 047cfe2f9d
commit 862e2b66fe
2 changed files with 19 additions and 6 deletions

View File

@ -234,7 +234,7 @@ S9xBasename (const char *f)
const char *
S9xBasenameNoExt (const char *f)
{
static char filename[PATH_MAX + 1];
static char filename[PATH_MAX];
const char *base, *ext;
if (!(base = strrchr (f, SLASH_CHAR)))
@ -245,11 +245,11 @@ S9xBasenameNoExt (const char *f)
ext = strrchr (f, '.');
if (!ext)
strncpy (filename, base, PATH_MAX);
sstrncpy (filename, base, PATH_MAX);
else
{
int len = ext - base;
strncpy (filename, base, len);
sstrncpy (filename, base, len);
filename[len] = '\0';
}
@ -284,7 +284,7 @@ S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
{
strncpy (filename, fname, PATH_MAX);
sstrncpy (filename, fname, PATH_MAX + 1);
if (!file_exists (filename))
{

17
port.h
View File

@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <limits.h>
#ifndef __LIBRETRO__
#include <memory.h>
@ -148,8 +149,20 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
#endif // __LIBRETRO__
#endif // __WIN32__
#define ssnprintf(dst, size, fmt, ...) if (snprintf(dst, size, fmt, __VA_ARGS__) >= (int) size) dst[size - 1] = '\0';
#define sstrncpy(dst, src, size) strncpy(dst, src, size - 1); dst[size - 1] = '\0';
inline void ssnprintf(char *dst, size_t size, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
if (vsnprintf(dst, size, fmt, args) >= (int) size)
dst[size - 1] = '\0';
va_end(args);
}
inline void sstrncpy(char *dst, const char *src, size_t size)
{
strncpy(dst, src, size - 1);
dst[size - 1] = '\0';
}
#if defined(__DJGPP) || defined(__WIN32__)
#define SLASH_STR "\\"