Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge iconv const changes from 1.2

I'm not entirely happy with them.  Maybe the right way to go is to leave
SDL_iconv() taking a non-const inbuf?  How often are we converting const
strings anyway?
  • Loading branch information
slouken committed Jun 28, 2007
1 parent 7e9c566 commit f56cad45925eec9637c08dfedfb45e2bef594f88
Showing with 24 additions and 12 deletions.
  1. +3 −6 include/SDL_stdinc.h
  2. +21 −6 src/stdlib/SDL_iconv.c
@@ -640,24 +640,21 @@ extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen,
#define SDL_iconv_t iconv_t
#define SDL_iconv_open iconv_open
#define SDL_iconv_close iconv_close
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf,
size_t * inbytesleft, char **outbuf,
size_t * outbytesleft);
#else
typedef struct _SDL_iconv_t *SDL_iconv_t;
extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
const char *fromcode);
extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, char **inbuf,
#endif
extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
size_t * inbytesleft, char **outbuf,
size_t * outbytesleft);
#endif
/* This function converts a string between encodings in one pass, returning a
string that must be freed with SDL_free() or NULL on error.
*/
extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
const char *fromcode,
char *inbuf,
const char *inbuf,
size_t inbytesleft);
#define SDL_iconv_utf8_ascii(S) SDL_iconv_string("ASCII", "UTF-8", S, SDL_strlen(S)+1)
#define SDL_iconv_utf8_latin1(S) SDL_iconv_string("LATIN1", "UTF-8", S, SDL_strlen(S)+1)
@@ -32,10 +32,24 @@

size_t
SDL_iconv(SDL_iconv_t cd,
char **inbuf, size_t * inbytesleft,
const char **inbuf, size_t * inbytesleft,
char **outbuf, size_t * outbytesleft)
{
size_t retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
size_t retCode;
#ifdef ICONV_REALLY_MODIFIES_INBUF
if (inbuf && *inbuf && inbytesleft) {
char *tmp = SDL_stack_alloc(char, *inbytesleft);
char *ptr = tmp;
SDL_memcpy(tmp, inbuf, *inbytesleft);
retCode = iconv(cd, &ptr, inbytesleft, outbuf, outbytesleft);
inbuf += (ptr - tmp);
SDL_stack_free(tmp);
} else {
retCode = iconv(cd, NULL, inbytesleft, outbuf, outbytesleft);
}
#else
retCode = iconv(cd, (char **) inbuf, inbytesleft, outbuf, outbytesleft);
#endif
if (retCode == (size_t) - 1) {
switch (errno) {
case E2BIG:
@@ -154,13 +168,14 @@ SDL_iconv_open(const char *tocode, const char *fromcode)

size_t
SDL_iconv(SDL_iconv_t cd,
char **inbuf, size_t * inbytesleft,
const char **inbuf, size_t * inbytesleft,
char **outbuf, size_t * outbytesleft)
{
/* For simplicity, we'll convert everything to and from UCS-4 */
char *src, *dst;
const char *src;
char *dst;
size_t srclen, dstlen;
Uint32 ch;
Uint32 ch = 0;
size_t total;

if (!inbuf || !*inbuf) {
@@ -755,7 +770,7 @@ SDL_iconv_close(SDL_iconv_t cd)
#endif /* !HAVE_ICONV */

char *
SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf,
SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
size_t inbytesleft)
{
SDL_iconv_t cd;

0 comments on commit f56cad4

Please sign in to comment.