aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ic/c_src/oe_ei_decode_wstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ic/c_src/oe_ei_decode_wstring.c')
-rw-r--r--lib/ic/c_src/oe_ei_decode_wstring.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/lib/ic/c_src/oe_ei_decode_wstring.c b/lib/ic/c_src/oe_ei_decode_wstring.c
new file mode 100644
index 0000000000..b89922f4b8
--- /dev/null
+++ b/lib/ic/c_src/oe_ei_decode_wstring.c
@@ -0,0 +1,107 @@
+/*
+ * %CopyrightBegin%
+ *
+ * Copyright Ericsson AB 1999-2009. All Rights Reserved.
+ *
+ * The contents of this file are subject to the Erlang Public License,
+ * Version 1.1, (the "License"); you may not use this file except in
+ * compliance with the License. You should have received a copy of the
+ * Erlang Public License along with this software. If not, it can be
+ * retrieved online at http://www.erlang.org/.
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * %CopyrightEnd%
+ *
+ */
+#include <ic.h>
+
+
+/* Scratch function */
+int oe_ei_decode_wstring(const char *buf, int *index, CORBA_wchar *p) {
+
+ int length,error_code,type,tmp=0;
+ char * tmp_space = NULL;
+
+
+ if ((error_code = ei_get_type(buf, index, &type, &length)) < 0)
+ return error_code;
+
+ switch(type) {
+
+ case ERL_LIST_EXT: /* A list */
+ case ERL_NIL_EXT: /* An empty list */
+
+ if (p) { /* Decoding part */
+
+ if ((error_code = ei_decode_list_header(buf, index, &length)) < 0)
+ return error_code;
+
+ if (length != 0) {
+ for(tmp = 0; tmp < length; tmp++)
+ if ((error_code = oe_ei_decode_wchar(buf, index, &(p[tmp]))) < 0)
+ return error_code;
+
+ /* Read list tail also */
+ if ((error_code = ei_decode_list_header(buf, index, &length)) < 0)
+ return error_code;
+ }
+
+ p[tmp] = 0; /* Wide NULL */
+
+ } else { /* Allocation counting part */
+
+ if ((error_code = ei_decode_list_header(buf, index, &length)) < 0)
+ return error_code;
+
+ if (length != 0) {
+ for(tmp = 0; tmp < length; tmp++)
+ if ((error_code = oe_ei_decode_wchar(buf, index, 0)) < 0)
+ return error_code;
+
+ /* Read list tail also */
+ if ((error_code = ei_decode_list_header(buf, index, &length)) < 0)
+ return error_code;
+ }
+ }
+
+ break;
+
+ case ERL_STRING_EXT: /* A string */
+
+ if (p) { /* Decoding part */
+
+ /* Allocate temporary string */
+ tmp_space = (char*) malloc(length*(__OE_WCHARSZ__+1));
+
+ if ((error_code = ei_decode_string(buf, index, tmp_space)) < 0)
+ return error_code;
+
+ /* Assign characters to wide characters */
+ for(tmp = 0; tmp < length; tmp++)
+ p[tmp] = tmp_space[tmp];
+
+ p[tmp] = 0; /* Wide NULL */
+
+ /* Free temporary string */
+ CORBA_free(tmp_space);
+
+ } else { /* Allocation counting part */
+
+ if ((error_code = ei_decode_string(buf, index, 0)) < 0)
+ return error_code;
+
+ }
+ break;
+
+ default: /* Bad header */
+ return -1;
+ }
+
+ return 0;
+}
+
+