SDL  2.0
geniconv.h File Reference
#include <iconv.h>
+ Include dependency graph for geniconv.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define iconv_open   libiconv_open
 
#define iconv   libiconv
 
#define iconv_close   libiconv_close
 
#define iconv_clean   libiconv_clean
 

Functions

void libiconv_clean (void)
 
iconv_t libiconv_open (const char *tocode, const char *fromcode)
 
int libiconv_close (iconv_t cd)
 
size_t libiconv (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
 
int StrUTF8 (int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
 
char * StrUTF8New (int fToUTF8, char *pcStr, int cbStr)
 
void StrUTF8Free (char *pszStr)
 

Macro Definition Documentation

◆ iconv

#define iconv   libiconv

Definition at line 41 of file geniconv.h.

◆ iconv_clean

#define iconv_clean   libiconv_clean

Definition at line 48 of file geniconv.h.

◆ iconv_close

#define iconv_close   libiconv_close

Definition at line 46 of file geniconv.h.

◆ iconv_open

#define iconv_open   libiconv_open

Definition at line 36 of file geniconv.h.

Function Documentation

◆ libiconv()

size_t libiconv ( iconv_t  cd,
char **  inbuf,
size_t inbytesleft,
char **  outbuf,
size_t outbytesleft 
)

Definition at line 146 of file geniconv.c.

148 {
149  return fn_iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
150 }
static FNICONV fn_iconv
Definition: geniconv.c:61

References fn_iconv.

◆ libiconv_clean()

void libiconv_clean ( void  )

Definition at line 128 of file geniconv.c.

129 {
130  if (hmIconv != NULLHANDLE) {
131  DosFreeModule(hmIconv);
132  hmIconv = NULLHANDLE;
133 
135  fn_iconv = NULL;
137  }
138 }
#define NULL
Definition: begin_code.h:163
static FNICONV_CLOSE fn_iconv_close
Definition: geniconv.c:62
static HMODULE hmIconv
Definition: geniconv.c:58
static FNICONV_OPEN fn_iconv_open
Definition: geniconv.c:60

References fn_iconv, fn_iconv_close, fn_iconv_open, hmIconv, and NULL.

◆ libiconv_close()

int libiconv_close ( iconv_t  cd)

Definition at line 152 of file geniconv.c.

153 {
154  return fn_iconv_close(cd);
155 }

References fn_iconv_close.

◆ libiconv_open()

iconv_t libiconv_open ( const char *  tocode,
const char *  fromcode 
)

Definition at line 140 of file geniconv.c.

141 {
142  _init();
143  return fn_iconv_open(tocode, fromcode);
144 }
static void _init(void)
Definition: geniconv.c:105

References _init(), and fn_iconv_open.

◆ StrUTF8()

int StrUTF8 ( int  fToUTF8,
char *  pcDst,
int  cbDst,
char *  pcSrc,
int  cbSrc 
)

Definition at line 25 of file sys2utf8.c.

26 {
27  size_t rc;
28  char *pcDstStart = pcDst;
29  iconv_t cd;
30  char *pszToCP, *pszFromCP;
31  int fError = 0;
32 
33  if (cbDst < 4)
34  return -1;
35 
36  if (fToUTF8) {
37  pszToCP = "UTF-8";
38  pszFromCP = "";
39  } else {
40  pszToCP = "";
41  pszFromCP = "UTF-8";
42  }
43 
44  cd = iconv_open(pszToCP, pszFromCP);
45  if (cd == (iconv_t)-1)
46  return -1;
47 
48  while (cbSrc > 0) {
49  rc = iconv(cd, &pcSrc, (size_t *)&cbSrc, &pcDst, (size_t *)&cbDst);
50  if (rc == (size_t)-1) {
51  if (errno == EILSEQ) {
52  /* Try to skip invalid character */
53  pcSrc++;
54  cbSrc--;
55  continue;
56  }
57 
58  fError = 1;
59  break;
60  }
61  }
62 
63  iconv_close(cd);
64 
65  /* Write trailing ZERO (1 byte for UTF-8, 2 bytes for the system cp) */
66  if (fToUTF8) {
67  if (cbDst < 1) {
68  pcDst--;
69  fError = 1; /* The destination buffer overflow */
70  }
71  *pcDst = '\0';
72  } else {
73  if (cbDst < 2) {
74  pcDst -= (cbDst == 0)? 2 : 1;
75  fError = 1; /* The destination buffer overflow */
76  }
77  *((short *)pcDst) = '\0';
78  }
79 
80  return (fError) ? -1 : (pcDst - pcDstStart);
81 }
void * iconv_t
Definition: iconv.h:7
int iconv_close(iconv_t)
iconv_t iconv_open(const char *, const char *)
size_t iconv(iconv_t, char **, size_t *, char **, size_t *)

References iconv(), iconv_close(), and iconv_open().

Referenced by main(), and StrUTF8New().

◆ StrUTF8Free()

void StrUTF8Free ( char *  pszStr)

Definition at line 102 of file sys2utf8.c.

103 {
104  free(pszStr);
105 }
SDL_EventEntry * free
Definition: SDL_events.c:89

References free.

◆ StrUTF8New()

char* StrUTF8New ( int  fToUTF8,
char *  pcStr,
int  cbStr 
)

Definition at line 83 of file sys2utf8.c.

84 {
85  int cbNewStr = (((cbStr > 4)? cbStr : 4) + 1) * 2;
86  char *pszNewStr = (char *) malloc(cbNewStr);
87 
88  if (pszNewStr == NULL)
89  return NULL;
90 
91  cbNewStr = StrUTF8(fToUTF8, pszNewStr, cbNewStr, pcStr, cbStr);
92  if (cbNewStr != -1) {
93  pcStr = (char *) realloc(pszNewStr, cbNewStr + ((fToUTF8)? 1 : sizeof(short)));
94  if (pcStr)
95  return pcStr;
96  }
97 
98  free(pszNewStr);
99  return NULL;
100 }
#define malloc
Definition: SDL_qsort.c:46
int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc)
Definition: sys2utf8.c:25

References free, malloc, NULL, and StrUTF8().

Referenced by main().