Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added SDL_wcslcpy and SDL_wcslcat.
Browse files Browse the repository at this point in the history
  • Loading branch information
dewyatt committed Aug 3, 2010
1 parent b042dd7 commit a02c196
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/SDL_stdinc.h
Expand Up @@ -470,6 +470,19 @@ extern DECLSPEC size_t SDLCALL SDL_strlen(const char *string);
extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t * string);
#endif

#ifdef HAVE_WCSLCPY
#define SDL_wcslcpy wcslcpy
#else
extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
#endif

#ifdef HAVE_WCSLCAT
#define SDL_wcslcat wcslcat
#else
extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
#endif


#ifdef HAVE_STRLCPY
#define SDL_strlcpy strlcpy
#else
Expand Down
27 changes: 27 additions & 0 deletions src/stdlib/SDL_string.c
Expand Up @@ -363,6 +363,33 @@ SDL_wcslen(const wchar_t * string)
}
#endif

#ifndef HAVE_WCSLCPY
size_t
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
{
size_t srclen = SDL_wcslen(src);
if (maxlen > 0) {
size_t len = SDL_min(srclen, maxlen - 1);
SDL_memcpy(dst, src, len * sizeof(wchar_t));
dst[len] = '\0';
}
return srclen;
}
#endif

#ifndef HAVE_WCSLCAT
size_t
SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
{
size_t dstlen = SDL_wcslen(dst);
size_t srclen = SDL_wcslen(src);
if (dstlen < maxlen) {
SDL_wcslcpy(dst + dstlen, src, maxlen - dstlen);
}
return dstlen + srclen;
}
#endif

#ifndef HAVE_STRLCPY
size_t
SDL_strlcpy(char *dst, const char *src, size_t maxlen)
Expand Down

0 comments on commit a02c196

Please sign in to comment.