s3:torture: call fault_setup() to get usage backtraces
[Samba/gebeck_regimport.git] / lib / util / charset / weird.c
blob7f766417dc4833bcbceb4dd5b33fb0625a877455
1 /*
2 Unix SMB/CIFS implementation.
3 Samba module with developer tools
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2002
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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "charset_proto.h"
24 #ifdef DEVELOPER
26 static struct {
27 char from;
28 const char *to;
29 int len;
30 } weird_table[] = {
31 {'q', "^q^", 3},
32 {'Q', "^Q^", 3},
33 {0, NULL}
36 size_t weird_pull(void *cd, const char **inbuf, size_t *inbytesleft,
37 char **outbuf, size_t *outbytesleft)
39 while (*inbytesleft >= 1 && *outbytesleft >= 2) {
40 int i;
41 int done = 0;
42 for (i=0;weird_table[i].from;i++) {
43 if (strncmp((*inbuf),
44 weird_table[i].to,
45 weird_table[i].len) == 0) {
46 if (*inbytesleft < weird_table[i].len) {
47 DEBUG(0,("ERROR: truncated weird string\n"));
48 /* smb_panic("weird_pull"); */
50 } else {
51 (*outbuf)[0] = weird_table[i].from;
52 (*outbuf)[1] = 0;
53 (*inbytesleft) -= weird_table[i].len;
54 (*outbytesleft) -= 2;
55 (*inbuf) += weird_table[i].len;
56 (*outbuf) += 2;
57 done = 1;
58 break;
62 if (done) continue;
63 (*outbuf)[0] = (*inbuf)[0];
64 (*outbuf)[1] = 0;
65 (*inbytesleft) -= 1;
66 (*outbytesleft) -= 2;
67 (*inbuf) += 1;
68 (*outbuf) += 2;
71 if (*inbytesleft > 0) {
72 errno = E2BIG;
73 return -1;
76 return 0;
79 size_t weird_push(void *cd, const char **inbuf, size_t *inbytesleft,
80 char **outbuf, size_t *outbytesleft)
82 int ir_count=0;
84 while (*inbytesleft >= 2 && *outbytesleft >= 1) {
85 int i;
86 int done=0;
87 for (i=0;weird_table[i].from;i++) {
88 if ((*inbuf)[0] == weird_table[i].from &&
89 (*inbuf)[1] == 0) {
90 if (*outbytesleft < weird_table[i].len) {
91 DEBUG(0,("No room for weird character\n"));
92 /* smb_panic("weird_push"); */
93 } else {
94 memcpy(*outbuf, weird_table[i].to,
95 weird_table[i].len);
96 (*inbytesleft) -= 2;
97 (*outbytesleft) -= weird_table[i].len;
98 (*inbuf) += 2;
99 (*outbuf) += weird_table[i].len;
100 done = 1;
101 break;
105 if (done) continue;
107 (*outbuf)[0] = (*inbuf)[0];
108 if ((*inbuf)[1]) ir_count++;
109 (*inbytesleft) -= 2;
110 (*outbytesleft) -= 1;
111 (*inbuf) += 2;
112 (*outbuf) += 1;
115 if (*inbytesleft == 1) {
116 errno = EINVAL;
117 return -1;
120 if (*inbytesleft > 1) {
121 errno = E2BIG;
122 return -1;
125 return ir_count;
128 #else
129 void charset_weird_dummy(void);
130 void charset_weird_dummy(void)
132 return;
135 #endif