geniconv.h (2676B)
1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 */ 21 22 /* 23 Universal iconv implementation for OS/2. 24 25 Andrey Vasilkin, 2016. 26 */ 27 28 #ifndef GENICONV_H 29 #define GENICONV_H 30 31 #include <iconv.h> 32 33 #ifdef iconv_open 34 #undef iconv_open 35 #endif 36 #define iconv_open libiconv_open 37 38 #ifdef iconv 39 #undef iconv 40 #endif 41 #define iconv libiconv 42 43 #ifdef iconv_close 44 #undef iconv_close 45 #endif 46 #define iconv_close libiconv_close 47 48 #define iconv_clean libiconv_clean 49 50 /* Non-standard function for iconv to unload the used dynamic library */ 51 void libiconv_clean(void); 52 53 iconv_t libiconv_open (const char *tocode, const char *fromcode); 54 int libiconv_close(iconv_t cd); 55 size_t libiconv (iconv_t cd, char **inbuf, size_t *inbytesleft, 56 char **outbuf, size_t *outbytesleft); 57 58 /* System codepage <-> UTF-8 59 * 60 * StrUTF8() 61 * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to 62 * the system cp (fToUTF8 is 0). Converted ASCIIZ string will be placed at the 63 * buffer pcDst, up to cbDst - 1 (for sys->utf8) or 2 (for utf8->sys) bytes. 64 * Returns the number of bytes written into pcDst, not counting the terminating 65 * 0 byte(s) or -1 on error. 66 */ 67 int StrUTF8(int fToUTF8, char *pcDst, int cbDst, char *pcSrc, int cbSrc); 68 69 /* StrUTF8New() 70 * Coverts string from system cp to UTF-8 (fToUTF8 is not 0) or from UTF-8 to 71 * the system cp (fToUTF8 is 0). Memory for the new string is obtained by 72 * using libc malloc(). 73 * Returns converted string, terminating two bytes 0 is appended to the result. 74 * Returns null on error. 75 */ 76 char *StrUTF8New(int fToUTF8, char *pcStr, int cbStr); 77 78 /* StrUTF8Free() 79 * Deallocates the memory block located by StrUTF8New() (just libc free()). 80 */ 81 void StrUTF8Free(char *pszStr); 82 83 #endif /* GENICONV_H */ 84 85 /* vi: set ts=4 sw=4 expandtab: */