2004-08-09 08:45:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) Ian F. Darwin 1986-1995.
|
|
|
|
* Software written by Ian F. Darwin and others;
|
|
|
|
* maintained 1995-present by Christos Zoulas and others.
|
2009-05-02 06:25:51 +00:00
|
|
|
*
|
2004-08-09 08:45:41 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice immediately at the beginning of the file, without modification,
|
|
|
|
* this list of conditions, and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2009-05-02 06:25:51 +00:00
|
|
|
*
|
2004-08-09 08:45:41 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2000-11-05 08:33:55 +00:00
|
|
|
/*
|
|
|
|
* ASCII magic -- file types that we know based on keywords
|
|
|
|
* that can appear anywhere in the file.
|
|
|
|
*
|
|
|
|
* Extensively modified by Eric Fischer <enf@pobox.com> in July, 2000,
|
|
|
|
* to handle character codes other than ASCII on a unified basis.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "file.h"
|
2009-05-02 06:25:51 +00:00
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
FILE_RCSID("@(#)$File: ascmagic.c,v 1.75 2009/02/03 20:27:51 christos Exp $")
|
|
|
|
#endif /* lint */
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
#include "magic.h"
|
2000-11-05 08:33:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <memory.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include "names.h"
|
|
|
|
|
|
|
|
#define MAXLINELEN 300 /* longest sane line length */
|
|
|
|
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
|
|
|
|
|| (x) == 0x85 || (x) == '\f')
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
private int ascmatch(const unsigned char *, const unichar *, size_t);
|
2009-01-02 02:57:16 +00:00
|
|
|
private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
|
2009-05-02 06:25:51 +00:00
|
|
|
private size_t trim_nuls(const unsigned char *, size_t);
|
2004-08-09 08:45:41 +00:00
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
/*
|
|
|
|
* Undo the NUL-termination kindly provided by process()
|
|
|
|
* but leave at least one byte to look at
|
|
|
|
*/
|
|
|
|
private size_t
|
|
|
|
trim_nuls(const unsigned char *buf, size_t nbytes)
|
|
|
|
{
|
|
|
|
while (nbytes > 1 && buf[nbytes - 1] == '\0')
|
|
|
|
nbytes--;
|
|
|
|
|
|
|
|
return nbytes;
|
|
|
|
}
|
2004-08-09 08:45:41 +00:00
|
|
|
|
|
|
|
protected int
|
|
|
|
file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
|
2000-11-05 08:33:55 +00:00
|
|
|
{
|
2009-05-02 06:25:51 +00:00
|
|
|
unichar *ubuf = NULL;
|
|
|
|
size_t ulen;
|
|
|
|
int rv = 1;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
const char *code = NULL;
|
|
|
|
const char *code_mime = NULL;
|
|
|
|
const char *type = NULL;
|
2009-05-02 06:25:51 +00:00
|
|
|
|
|
|
|
if (ms->flags & MAGIC_APPLE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nbytes = trim_nuls(buf, nbytes);
|
|
|
|
|
|
|
|
/* If file doesn't look like any sort of text, give up. */
|
|
|
|
if (file_encoding(ms, buf, nbytes, &ubuf, &ulen, &code, &code_mime,
|
|
|
|
&type) == 0) {
|
|
|
|
rv = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
|
|
|
|
type);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (ubuf)
|
|
|
|
free(ubuf);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int
|
|
|
|
file_ascmagic_with_encoding(struct magic_set *ms, const unsigned char *buf,
|
|
|
|
size_t nbytes, unichar *ubuf, size_t ulen, const char *code,
|
|
|
|
const char *type)
|
|
|
|
{
|
|
|
|
unsigned char *utf8_buf = NULL, *utf8_end;
|
|
|
|
size_t mlen, i;
|
|
|
|
const struct names *p;
|
|
|
|
int rv = -1;
|
|
|
|
int mime = ms->flags & MAGIC_MIME;
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
const char *subtype = NULL;
|
|
|
|
const char *subtype_mime = NULL;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
int has_escapes = 0;
|
|
|
|
int has_backspace = 0;
|
2006-06-19 07:52:15 +00:00
|
|
|
int seen_cr = 0;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
int n_crlf = 0;
|
|
|
|
int n_lf = 0;
|
|
|
|
int n_cr = 0;
|
|
|
|
int n_nel = 0;
|
|
|
|
|
2007-05-24 21:59:38 +00:00
|
|
|
size_t last_line_end = (size_t)-1;
|
2000-11-05 08:33:55 +00:00
|
|
|
int has_long_lines = 0;
|
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
if (ms->flags & MAGIC_APPLE)
|
|
|
|
return 0;
|
2004-08-09 08:45:41 +00:00
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
nbytes = trim_nuls(buf, nbytes);
|
2000-11-05 08:33:55 +00:00
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
/* If we have fewer than 2 bytes, give up. */
|
2006-06-19 07:52:15 +00:00
|
|
|
if (nbytes <= 1) {
|
|
|
|
rv = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* Convert ubuf to UTF-8 and try text soft magic */
|
|
|
|
/* malloc size is a conservative overestimate; could be
|
2009-05-02 06:25:51 +00:00
|
|
|
improved, or at least realloced after conversion. */
|
2009-01-02 02:57:16 +00:00
|
|
|
mlen = ulen * 6;
|
|
|
|
if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) {
|
|
|
|
file_oomem(ms, mlen);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
|
|
|
|
goto done;
|
2009-05-02 06:25:51 +00:00
|
|
|
if ((rv = file_softmagic(ms, utf8_buf, (size_t)(utf8_end - utf8_buf),
|
|
|
|
TEXTTEST)) != 0)
|
2009-01-02 02:57:16 +00:00
|
|
|
goto done;
|
2009-05-02 06:25:51 +00:00
|
|
|
else
|
|
|
|
rv = -1;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
/* look for tokens from names.h - this is expensive! */
|
2007-05-24 21:59:38 +00:00
|
|
|
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
|
|
|
|
goto subtype_identified;
|
|
|
|
|
2000-11-05 08:33:55 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < ulen) {
|
2004-08-09 08:45:41 +00:00
|
|
|
size_t end;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* skip past any leading space */
|
2000-11-05 08:33:55 +00:00
|
|
|
while (i < ulen && ISSPC(ubuf[i]))
|
|
|
|
i++;
|
|
|
|
if (i >= ulen)
|
|
|
|
break;
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* find the next whitespace */
|
2000-11-05 08:33:55 +00:00
|
|
|
for (end = i + 1; end < nbytes; end++)
|
|
|
|
if (ISSPC(ubuf[end]))
|
|
|
|
break;
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* compare the word thus isolated against the token list */
|
2000-11-05 08:33:55 +00:00
|
|
|
for (p = names; p < names + NNAMES; p++) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (ascmatch((const unsigned char *)p->name, ubuf + i,
|
2003-02-15 18:53:17 +00:00
|
|
|
end - i)) {
|
2000-11-05 08:33:55 +00:00
|
|
|
subtype = types[p->type].human;
|
|
|
|
subtype_mime = types[p->type].mime;
|
|
|
|
goto subtype_identified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
subtype_identified:
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/* Now try to discover other details about the file. */
|
2000-11-05 08:33:55 +00:00
|
|
|
for (i = 0; i < ulen; i++) {
|
2006-06-19 07:52:15 +00:00
|
|
|
if (ubuf[i] == '\n') {
|
|
|
|
if (seen_cr)
|
|
|
|
n_crlf++;
|
|
|
|
else
|
|
|
|
n_lf++;
|
2000-11-05 08:33:55 +00:00
|
|
|
last_line_end = i;
|
2006-06-19 07:52:15 +00:00
|
|
|
} else if (seen_cr)
|
2000-11-05 08:33:55 +00:00
|
|
|
n_cr++;
|
2006-06-19 07:52:15 +00:00
|
|
|
|
|
|
|
seen_cr = (ubuf[i] == '\r');
|
|
|
|
if (seen_cr)
|
2000-11-05 08:33:55 +00:00
|
|
|
last_line_end = i;
|
2006-06-19 07:52:15 +00:00
|
|
|
|
2000-11-05 08:33:55 +00:00
|
|
|
if (ubuf[i] == 0x85) { /* X3.64/ECMA-43 "next line" character */
|
|
|
|
n_nel++;
|
|
|
|
last_line_end = i;
|
|
|
|
}
|
2006-06-19 07:52:15 +00:00
|
|
|
|
|
|
|
/* If this line is _longer_ than MAXLINELEN, remember it. */
|
|
|
|
if (i > last_line_end + MAXLINELEN)
|
|
|
|
has_long_lines = 1;
|
|
|
|
|
|
|
|
if (ubuf[i] == '\033')
|
|
|
|
has_escapes = 1;
|
|
|
|
if (ubuf[i] == '\b')
|
|
|
|
has_backspace = 1;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 07:52:15 +00:00
|
|
|
/* Beware, if the data has been truncated, the final CR could have
|
|
|
|
been followed by a LF. If we have HOWMANY bytes, it indicates
|
|
|
|
that the data might have been truncated, probably even before
|
|
|
|
this function was called. */
|
|
|
|
if (seen_cr && nbytes < HOWMANY)
|
|
|
|
n_cr++;
|
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
if (strcmp(type, "binary") == 0) {
|
|
|
|
rv = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
2008-01-13 20:35:16 +00:00
|
|
|
if (mime) {
|
2009-05-02 06:25:51 +00:00
|
|
|
if ((mime & MAGIC_MIME_TYPE) != 0) {
|
2008-01-13 20:35:16 +00:00
|
|
|
if (subtype_mime) {
|
2009-05-02 06:25:51 +00:00
|
|
|
if (file_printf(ms, "%s", subtype_mime) == -1)
|
2008-01-13 20:35:16 +00:00
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
if (file_printf(ms, "text/plain") == -1)
|
|
|
|
goto done;
|
|
|
|
}
|
2004-08-09 08:45:41 +00:00
|
|
|
}
|
2000-11-05 08:33:55 +00:00
|
|
|
} else {
|
2009-05-02 06:25:51 +00:00
|
|
|
if (file_printf(ms, "%s", code) == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
if (subtype) {
|
2009-05-02 06:25:51 +00:00
|
|
|
if (file_printf(ms, " %s", subtype) == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
if (file_printf(ms, " %s", type) == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
if (has_long_lines)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ", with very long lines") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only report line terminators if we find one other than LF,
|
|
|
|
* or if we find none at all.
|
|
|
|
*/
|
|
|
|
if ((n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) ||
|
|
|
|
(n_crlf != 0 || n_cr != 0 || n_nel != 0)) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ", with") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
|
2009-05-02 06:25:51 +00:00
|
|
|
if (n_crlf == 0 && n_cr == 0 && n_nel == 0 && n_lf == 0) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " no") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2004-08-09 08:45:41 +00:00
|
|
|
} else {
|
2000-11-05 08:33:55 +00:00
|
|
|
if (n_crlf) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " CRLF") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
if (n_cr || n_lf || n_nel)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ",") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
if (n_cr) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " CR") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
if (n_lf || n_nel)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ",") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
if (n_lf) {
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " LF") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
if (n_nel)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ",") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
if (n_nel)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " NEL") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, " line terminators") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_escapes)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ", with escape sequences") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
if (has_backspace)
|
2004-08-09 08:45:41 +00:00
|
|
|
if (file_printf(ms, ", with overstriking") == -1)
|
2006-06-19 07:52:15 +00:00
|
|
|
goto done;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
2006-06-19 07:52:15 +00:00
|
|
|
rv = 1;
|
|
|
|
done:
|
2009-01-02 02:57:16 +00:00
|
|
|
if (utf8_buf)
|
|
|
|
free(utf8_buf);
|
2006-06-19 07:52:15 +00:00
|
|
|
|
|
|
|
return rv;
|
2000-11-05 08:33:55 +00:00
|
|
|
}
|
|
|
|
|
2004-08-09 08:45:41 +00:00
|
|
|
private int
|
|
|
|
ascmatch(const unsigned char *s, const unichar *us, size_t ulen)
|
2000-11-05 08:33:55 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < ulen; i++) {
|
|
|
|
if (s[i] != us[i])
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s[i])
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-01-02 02:57:16 +00:00
|
|
|
/*
|
|
|
|
* Encode Unicode string as UTF-8, returning pointer to character
|
|
|
|
* after end of string, or NULL if an invalid character is found.
|
|
|
|
*/
|
|
|
|
private unsigned char *
|
|
|
|
encode_utf8(unsigned char *buf, size_t len, unichar *ubuf, size_t ulen)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
unsigned char *end = buf + len;
|
|
|
|
|
|
|
|
for (i = 0; i < ulen; i++) {
|
|
|
|
if (ubuf[i] <= 0x7f) {
|
|
|
|
if (end - buf < 1)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)ubuf[i];
|
|
|
|
} else if (ubuf[i] <= 0x7ff) {
|
|
|
|
if (end - buf < 2)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] >> 6) + 0xc0);
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
|
|
|
} else if (ubuf[i] <= 0xffff) {
|
|
|
|
if (end - buf < 3)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] >> 12) + 0xe0);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
|
|
|
} else if (ubuf[i] <= 0x1fffff) {
|
|
|
|
if (end - buf < 4)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] >> 18) + 0xf0);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
|
|
|
} else if (ubuf[i] <= 0x3ffffff) {
|
|
|
|
if (end - buf < 5)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] >> 24) + 0xf8);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
|
|
|
} else if (ubuf[i] <= 0x7fffffff) {
|
|
|
|
if (end - buf < 6)
|
|
|
|
return NULL;
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] >> 30) + 0xfc);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 24) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 18) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 12) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)(((ubuf[i] >> 6) & 0x3f) + 0x80);
|
|
|
|
*buf++ = (unsigned char)((ubuf[i] & 0x3f) + 0x80);
|
|
|
|
} else /* Invalid character */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|