mirror of https://github.com/snes9xgit/snes9x.git
Turn these into inline functions for sanity.
This commit is contained in:
parent
047cfe2f9d
commit
862e2b66fe
|
@ -234,7 +234,7 @@ S9xBasename (const char *f)
|
||||||
const char *
|
const char *
|
||||||
S9xBasenameNoExt (const char *f)
|
S9xBasenameNoExt (const char *f)
|
||||||
{
|
{
|
||||||
static char filename[PATH_MAX + 1];
|
static char filename[PATH_MAX];
|
||||||
const char *base, *ext;
|
const char *base, *ext;
|
||||||
|
|
||||||
if (!(base = strrchr (f, SLASH_CHAR)))
|
if (!(base = strrchr (f, SLASH_CHAR)))
|
||||||
|
@ -245,11 +245,11 @@ S9xBasenameNoExt (const char *f)
|
||||||
ext = strrchr (f, '.');
|
ext = strrchr (f, '.');
|
||||||
|
|
||||||
if (!ext)
|
if (!ext)
|
||||||
strncpy (filename, base, PATH_MAX);
|
sstrncpy (filename, base, PATH_MAX);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int len = ext - base;
|
int len = ext - base;
|
||||||
strncpy (filename, base, len);
|
sstrncpy (filename, base, len);
|
||||||
filename[len] = '\0';
|
filename[len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
|
||||||
|
|
||||||
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
|
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
|
||||||
{
|
{
|
||||||
strncpy (filename, fname, PATH_MAX);
|
sstrncpy (filename, fname, PATH_MAX + 1);
|
||||||
|
|
||||||
if (!file_exists (filename))
|
if (!file_exists (filename))
|
||||||
{
|
{
|
||||||
|
|
17
port.h
17
port.h
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#ifndef __LIBRETRO__
|
#ifndef __LIBRETRO__
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
@ -148,8 +149,20 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
|
||||||
#endif // __LIBRETRO__
|
#endif // __LIBRETRO__
|
||||||
#endif // __WIN32__
|
#endif // __WIN32__
|
||||||
|
|
||||||
#define ssnprintf(dst, size, fmt, ...) if (snprintf(dst, size, fmt, __VA_ARGS__) >= (int) size) dst[size - 1] = '\0';
|
inline void ssnprintf(char *dst, size_t size, const char *fmt, ...)
|
||||||
#define sstrncpy(dst, src, size) strncpy(dst, src, size - 1); dst[size - 1] = '\0';
|
{
|
||||||
|
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__)
|
#if defined(__DJGPP) || defined(__WIN32__)
|
||||||
#define SLASH_STR "\\"
|
#define SLASH_STR "\\"
|
||||||
|
|
Loading…
Reference in New Issue