Skip to content

Commit

Permalink
Remove g_mbstowcs() and g_wcstombs()
Browse files Browse the repository at this point in the history
These calls are now replaced with explicit UTF conversion routines in
the common/string_calls.[hc] and common/parse.[hc] modules.

Also removed:-
- The support code in common/os_calls.c to set the locale to use
  these routines.
- The twchar type in arch.h
  • Loading branch information
matt335672 authored and seflerZ committed May 3, 2024
1 parent 7146025 commit c6b84f7
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 43 deletions.
4 changes: 1 addition & 3 deletions common/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ typedef bool_t tbool;
typedef intptr_t tbus;
typedef intptr_t tintptr;

/* wide char, socket */
/* socket */
#if defined(_WIN32)
typedef unsigned short twchar;
typedef unsigned int tsock;
#else
typedef int twchar;
typedef int tsock;
#endif
#endif /* DEFINED_Ts */
Expand Down
14 changes: 0 additions & 14 deletions common/os_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,6 @@ g_init(const char *app_name)

WSAStartup(2, &wsadata);
#endif

/* In order to get g_mbstowcs and g_wcstombs to work properly with
UTF-8 non-ASCII characters, LC_CTYPE cannot be "C" or blank.
To select UTF-8 encoding without specifying any countries/languages,
"C.UTF-8" is used but provided in few systems.
See also: https://sourceware.org/glibc/wiki/Proposals/C.UTF-8 */
char *lc_ctype;
lc_ctype = setlocale(LC_CTYPE, "C.UTF-8");
if (lc_ctype == NULL)
{
/* use en_US.UTF-8 instead if not available */
setlocale(LC_CTYPE, "en_US.UTF-8");
}
}

/*****************************************************************************/
Expand Down
24 changes: 0 additions & 24 deletions common/string_calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,30 +710,6 @@ g_strstr(const char *haystack, const char *needle)
return (char *)strstr(haystack, needle);
}

/*****************************************************************************/
int
g_mbstowcs(twchar *dest, const char *src, int n)
{
wchar_t *ldest;
int rv;

ldest = (wchar_t *)dest;
rv = mbstowcs(ldest, src, n);
return rv;
}

/*****************************************************************************/
int
g_wcstombs(char *dest, const twchar *src, int n)
{
const wchar_t *lsrc;
int rv;

lsrc = (const wchar_t *)src;
rv = wcstombs(dest, lsrc, n);
return rv;
}

/*****************************************************************************/
/* returns error */
int
Expand Down
2 changes: 0 additions & 2 deletions common/string_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ int g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str);
int g_pos(const char *str, const char *to_find);
char *g_strstr(const char *haystack, const char *needle);
int g_mbstowcs(twchar *dest, const char *src, int n);
int g_wcstombs(char *dest, const twchar *src, int n);

/** trim spaces and tabs, anything <= space
*
Expand Down

0 comments on commit c6b84f7

Please sign in to comment.