diff options
Diffstat (limited to 'src/charset/codecs/codec_utf16.c')
-rw-r--r-- | src/charset/codecs/codec_utf16.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/charset/codecs/codec_utf16.c b/src/charset/codecs/codec_utf16.c index c2a91ed..0b8379a 100644 --- a/src/charset/codecs/codec_utf16.c +++ b/src/charset/codecs/codec_utf16.c @@ -8,9 +8,10 @@ #include <stdlib.h> #include <string.h> -/* These two are for htonl / ntohl */ -#include <arpa/inet.h> +/* These three are for htonl / ntohl */ +#include <sys/types.h> #include <netinet/in.h> +#include <arpa/inet.h> #include <parserutils/charset/mibenum.h> #include <parserutils/charset/utf16.h> @@ -76,7 +77,7 @@ static inline parserutils_error charset_utf16_codec_output_decoded_char( */ bool charset_utf16_codec_handles_charset(const char *charset) { - return parserutils_charset_mibenum_from_name(charset, strlen(charset)) + return parserutils_charset_mibenum_from_name(charset, strlen(charset)) == parserutils_charset_mibenum_from_name("UTF-16", SLEN("UTF-16")); } @@ -152,7 +153,7 @@ parserutils_error charset_utf16_codec_destroy (parserutils_charset_codec *codec) * * On exit, ::source will point immediately _after_ the last input character * read. Any remaining output for the character will be buffered by the - * codec for writing on the next call. + * codec for writing on the next call. * * Note that, if failure occurs whilst attempting to write any output * buffered by the last call, then ::source and ::sourcelen will remain @@ -206,7 +207,7 @@ parserutils_error charset_utf16_codec_encode(parserutils_charset_codec *codec, /* Now process the characters for this call */ while (*sourcelen > 0) { - ucs4 = ntohl(*((uint32_t *) (void *) *source)); + ucs4 = (uint32_t) ntohl(*((uint32_t *) (void *) *source)); towrite = &ucs4; towritelen = 1; @@ -273,9 +274,9 @@ parserutils_error charset_utf16_codec_encode(parserutils_charset_codec *codec, * read, if the result is _OK or _NOMEM. Any remaining output for the * character will be buffered by the codec for writing on the next call. * - * In the case of the result being _INVALID, ::source will point _at_ the - * last input character read; nothing will be written or buffered for the - * failed character. It is up to the client to fix the cause of the failure + * In the case of the result being _INVALID, ::source will point _at_ the + * last input character read; nothing will be written or buffered for the + * failed character. It is up to the client to fix the cause of the failure * and retry the decoding process. * * Note that, if failure occurs whilst attempting to write any output @@ -309,7 +310,8 @@ parserutils_error charset_utf16_codec_decode(parserutils_charset_codec *codec, uint32_t *pread = c->read_buf; while (c->read_len > 0 && *destlen >= c->read_len * 4) { - *((uint32_t *) (void *) *dest) = htonl(pread[0]); + *((uint32_t *) (void *) *dest) = + (uint32_t) htonl(pread[0]); *dest += 4; *destlen -= 4; @@ -416,9 +418,9 @@ parserutils_error charset_utf16_codec_reset(parserutils_charset_codec *codec) * read, if the result is _OK or _NOMEM. Any remaining output for the * character will be buffered by the codec for writing on the next call. * - * In the case of the result being _INVALID, ::source will point _at_ the - * last input character read; nothing will be written or buffered for the - * failed character. It is up to the client to fix the cause of the failure + * In the case of the result being _INVALID, ::source will point _at_ the + * last input character read; nothing will be written or buffered for the + * failed character. It is up to the client to fix the cause of the failure * and retry the decoding process. * * ::sourcelen will be reduced appropriately on exit. @@ -436,7 +438,7 @@ parserutils_error charset_utf16_codec_read_char(charset_utf16_codec *c, parserutils_error error; /* Convert a single character */ - error = parserutils_charset_utf16_to_ucs4(*source, *sourcelen, + error = parserutils_charset_utf16_to_ucs4(*source, *sourcelen, &ucs4, &sucs4); if (error == PARSERUTILS_OK) { /* Read a character */ @@ -475,7 +477,7 @@ parserutils_error charset_utf16_codec_read_char(charset_utf16_codec *c, c->inval_len = 0; /* Strict errormode; simply flag invalid character */ - if (c->base.errormode == + if (c->base.errormode == PARSERUTILS_CHARSET_CODEC_ERROR_STRICT) { return PARSERUTILS_INVALID; } @@ -540,7 +542,7 @@ parserutils_error charset_utf16_codec_output_decoded_char(charset_utf16_codec *c return PARSERUTILS_NOMEM; } - *((uint32_t *) (void *) *dest) = htonl(ucs4); + *((uint32_t *) (void *) *dest) = (uint32_t) htonl(ucs4); *dest += 4; *destlen -= 4; |