YAZ 5.35.1
ucs4.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
10#if HAVE_CONFIG_H
11#include <config.h>
12#endif
13
14#include <assert.h>
15#include <errno.h>
16#include <string.h>
17
18#include "iconv-p.h"
19
20static unsigned long read_UCS4(yaz_iconv_t cd, yaz_iconv_decoder_t d,
21 unsigned char *inp,
22 size_t inbytesleft, size_t *no_read)
23{
24 unsigned long x = 0;
25
26 if (inbytesleft < 4)
27 {
28 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
29 *no_read = 0;
30 }
31 else
32 {
33 x = (inp[0]<<24) | (inp[1]<<16) | (inp[2]<<8) | inp[3];
34 *no_read = 4;
35 }
36 return x;
37}
38
39static unsigned long read_UCS4LE(yaz_iconv_t cd, yaz_iconv_decoder_t d,
40 unsigned char *inp,
41 size_t inbytesleft, size_t *no_read)
42{
43 unsigned long x = 0;
44
45 if (inbytesleft < 4)
46 {
47 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL); /* incomplete input */
48 *no_read = 0;
49 }
50 else
51 {
52 x = (inp[3]<<24) | (inp[2]<<16) | (inp[1]<<8) | inp[0];
53 *no_read = 4;
54 }
55 return x;
56}
57
59 unsigned long x,
60 char **outbuf, size_t *outbytesleft)
61{
62 unsigned char *outp = (unsigned char *) *outbuf;
63 if (*outbytesleft >= 4)
64 {
65 *outp++ = (unsigned char) (x>>24);
66 *outp++ = (unsigned char) (x>>16);
67 *outp++ = (unsigned char) (x>>8);
68 *outp++ = (unsigned char) x;
69 (*outbytesleft) -= 4;
70 }
71 else
72 {
74 return (size_t)(-1);
75 }
76 *outbuf = (char *) outp;
77 return 0;
78}
79
81 unsigned long x,
82 char **outbuf, size_t *outbytesleft)
83{
84 unsigned char *outp = (unsigned char *) *outbuf;
85 if (*outbytesleft >= 4)
86 {
87 *outp++ = (unsigned char) x;
88 *outp++ = (unsigned char) (x>>8);
89 *outp++ = (unsigned char) (x>>16);
90 *outp++ = (unsigned char) (x>>24);
91 (*outbytesleft) -= 4;
92 }
93 else
94 {
96 return (size_t)(-1);
97 }
98 *outbuf = (char *) outp;
99 return 0;
100}
101
102
105
106{
107 if (!yaz_matchstr(tocode, "UCS4"))
109 else if (!yaz_matchstr(tocode, "UCS4LE"))
111 else
112 return 0;
113 return e;
114}
115
118
119{
120 if (!yaz_matchstr(tocode, "UCS4"))
122 else if (!yaz_matchstr(tocode, "UCS4LE"))
124 else
125 return 0;
126 return d;
127}
128
129
130
131/*
132 * Local variables:
133 * c-basic-offset: 4
134 * c-file-style: "Stroustrup"
135 * indent-tabs-mode: nil
136 * End:
137 * vim: shiftwidth=4 tabstop=8 expandtab
138 */
139
Header for errno utilities.
Internal header for iconv.
void yaz_iconv_set_errno(yaz_iconv_t cd, int no)
Definition siconv.c:298
int yaz_matchstr(const char *s1, const char *s2)
match strings - independent of case and '-'
Definition matchstr.c:42
unsigned long(* read_handle)(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inbuf, size_t inbytesleft, size_t *no_read)
Definition iconv-p.h:86
size_t(* write_handle)(yaz_iconv_t cd, yaz_iconv_encoder_t e, unsigned long x, char **outbuf, size_t *outbytesleft)
Definition iconv-p.h:45
yaz_iconv_decoder_t yaz_ucs4_decoder(const char *tocode, yaz_iconv_decoder_t d)
Definition ucs4.c:116
static unsigned long read_UCS4(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read)
Definition ucs4.c:20
static size_t write_UCS4(yaz_iconv_t cd, yaz_iconv_encoder_t en, unsigned long x, char **outbuf, size_t *outbytesleft)
Definition ucs4.c:58
yaz_iconv_encoder_t yaz_ucs4_encoder(const char *tocode, yaz_iconv_encoder_t e)
Definition ucs4.c:103
static unsigned long read_UCS4LE(yaz_iconv_t cd, yaz_iconv_decoder_t d, unsigned char *inp, size_t inbytesleft, size_t *no_read)
Definition ucs4.c:39
static size_t write_UCS4LE(yaz_iconv_t cd, yaz_iconv_encoder_t en, unsigned long x, char **outbuf, size_t *outbytesleft)
Definition ucs4.c:80
#define YAZ_ICONV_E2BIG
error code: Not sufficient room for output buffer
Definition yaz-iconv.h:47
#define YAZ_ICONV_EINVAL
error code: An incomplete multibyte sequence is in input buffer
Definition yaz-iconv.h:51