summaryrefslogtreecommitdiff
path: root/src/encoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding.c')
-rw-r--r--src/encoding.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/encoding.c b/src/encoding.c
index 3c116cd74f176..3e7b9e584b08e 100644
--- a/src/encoding.c
+++ b/src/encoding.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: encoding.c,v 1.13 2015/06/04 19:16:28 christos Exp $")
+FILE_RCSID("@(#)$File: encoding.c,v 1.14 2017/11/02 20:25:39 christos Exp $")
#endif /* lint */
#include "magic.h"
@@ -66,11 +66,21 @@ private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
* ubuf, and the number of characters converted in ulen.
*/
protected int
-file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, unichar **ubuf, size_t *ulen, const char **code, const char **code_mime, const char **type)
+file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
+ size_t *ulen, const char **code, const char **code_mime, const char **type)
{
+ const unsigned char *buf = b->fbuf;
+ size_t nbytes = b->flen;
size_t mlen;
int rv = 1, ucs_type;
unsigned char *nbuf = NULL;
+ unichar *udefbuf;
+ size_t udeflen;
+
+ if (ubuf == NULL)
+ ubuf = &udefbuf;
+ if (ulen == NULL)
+ ulen = &udeflen;
*type = "text";
*ulen = 0;
@@ -144,6 +154,8 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
done:
free(nbuf);
+ if (ubuf == &udefbuf)
+ free(udefbuf);
return rv;
}