2 Unix SMB/CIFS implementation.
3 minimal iconv implementation
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2002,2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 From samba 3.0 beta and GNU libiconv-1.8
22 It's bad but most of the time we can't use libc iconv service:
23 - it doesn't round trip for most encoding
24 - it doesn't know about Apple extension
29 #endif /* HAVE_CONFIG_H */
34 #include <arpa/inet.h>
36 #include <atalk/unicode.h>
37 #include <atalk/logger.h>
39 #include "generic_mb.h"
40 #include "../byteorder.h"
43 /* ------------------------ */
45 size_t mb_generic_push( int (*char_func)(unsigned char *, ucs2_t), void *cd _U_, char **inbuf,
46 size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
49 unsigned char *tmpptr = (unsigned char *) *outbuf;
52 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
54 inval = SVAL((*inbuf),0);
55 if ( (char_func)( tmpptr, inval)) {
69 if (*inbytesleft > 0) {
77 /* ------------------------ */
79 size_t mb_generic_pull ( int (*char_func)(ucs2_t *, const unsigned char *), void *cd _U_,
80 char **inbuf, size_t *inbytesleft,char **outbuf, size_t *outbytesleft)
86 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
88 inptr = (unsigned char *) *inbuf;
89 if (char_func ( &temp, inptr)) {
90 SSVAL((*outbuf), 0, temp);
105 if (*inbytesleft > 0) {