Skip to content

fileinfo build fix proposal for haiku. #5983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/fileinfo/libmagic.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1610,8 +1610,8 @@ diff -u libmagic.orig/encoding.c libmagic/encoding.c
*code_mime = "binary";

mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
- if ((*ubuf = CAST(unichar *, calloc(CAST(size_t, 1), mlen))) == NULL) {
+ if ((*ubuf = CAST(unichar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
- if ((*ubuf = CAST(unicodechar *, calloc(CAST(size_t, 1), mlen))) == NULL) {
+ if ((*ubuf = CAST(unicodechar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
file_oomem(ms, mlen);
goto done;
}
Expand Down Expand Up @@ -1740,7 +1740,7 @@ diff -u libmagic.orig/file.h libmagic/file.h
(t) == FILE_BESTRING16 || \
@@ -447,28 +441,23 @@
/* Type for Unicode characters */
typedef unsigned long unichar;
typedef unsigned long unicodechar;

-struct stat;
#define FILE_T_LOCAL 1
Expand Down
8 changes: 4 additions & 4 deletions ext/fileinfo/libmagic/ascmagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ FILE_RCSID("@(#)$File: ascmagic.c,v 1.104 2019/05/07 02:27:11 christos Exp $")
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
|| (x) == 0x85 || (x) == '\f')

private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
private unsigned char *encode_utf8(unsigned char *, size_t, unicodechar *, size_t);
private size_t trim_nuls(const unsigned char *, size_t);

/*
Expand All @@ -70,7 +70,7 @@ trim_nuls(const unsigned char *buf, size_t nbytes)
protected int
file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)
{
unichar *ubuf = NULL;
unicodechar *ubuf = NULL;
size_t ulen = 0;
int rv = 1;
struct buffer bb;
Expand Down Expand Up @@ -103,7 +103,7 @@ file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)

protected int
file_ascmagic_with_encoding(struct magic_set *ms,
const struct buffer *b, unichar *ubuf, size_t ulen, const char *code,
const struct buffer *b, unicodechar *ubuf, size_t ulen, const char *code,
const char *type, int text)
{
struct buffer bb;
Expand Down Expand Up @@ -338,7 +338,7 @@ file_ascmagic_with_encoding(struct magic_set *ms,
* 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)
encode_utf8(unsigned char *buf, size_t len, unicodechar *ubuf, size_t ulen)
{
size_t i;
unsigned char *end = buf + len;
Expand Down
60 changes: 30 additions & 30 deletions ext/fileinfo/libmagic/encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ FILE_RCSID("@(#)$File: encoding.c,v 1.20 2019/04/15 16:48:41 christos Exp $")
#include <stdlib.h>


private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *);
private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *,
private int looks_ascii(const unsigned char *, size_t, unicodechar *, size_t *);
private int looks_utf8_with_BOM(const unsigned char *, size_t, unicodechar *,
size_t *);
private int looks_utf7(const unsigned char *, size_t, unichar *, size_t *);
private int looks_ucs16(const unsigned char *, size_t, unichar *, size_t *);
private int looks_ucs32(const unsigned char *, size_t, unichar *, size_t *);
private int looks_latin1(const unsigned char *, size_t, unichar *, size_t *);
private int looks_extended(const unsigned char *, size_t, unichar *, size_t *);
private int looks_utf7(const unsigned char *, size_t, unicodechar *, size_t *);
private int looks_ucs16(const unsigned char *, size_t, unicodechar *, size_t *);
private int looks_ucs32(const unsigned char *, size_t, unicodechar *, size_t *);
private int looks_latin1(const unsigned char *, size_t, unicodechar *, size_t *);
private int looks_extended(const unsigned char *, size_t, unicodechar *, size_t *);
private void from_ebcdic(const unsigned char *, size_t, unsigned char *);

#ifdef DEBUG_ENCODING
Expand All @@ -63,19 +63,19 @@ private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
/*
* Try to determine whether text is in some character code we can
* identify. Each of these tests, if it succeeds, will leave
* the text converted into one-unichar-per-character Unicode in
* the text converted into one-unicodechar-per-character Unicode in
* ubuf, and the number of characters converted in ulen.
*/
protected int
file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
file_encoding(struct magic_set *ms, const struct buffer *b, unicodechar **ubuf,
size_t *ulen, const char **code, const char **code_mime, const char **type)
{
const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
size_t nbytes = b->flen;
size_t mlen;
int rv = 1, ucs_type;
unsigned char *nbuf = NULL;
unichar *udefbuf;
unicodechar *udefbuf;
size_t udeflen;

if (ubuf == NULL)
Expand All @@ -89,7 +89,7 @@ file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
*code_mime = "binary";

mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
if ((*ubuf = CAST(unichar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
if ((*ubuf = CAST(unicodechar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
file_oomem(ms, mlen);
goto done;
}
Expand Down Expand Up @@ -251,7 +251,7 @@ private char text_chars[256] = {
};

private int
looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
looks_ascii(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
size_t *ulen)
{
size_t i;
Expand All @@ -271,7 +271,7 @@ looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
}

private int
looks_latin1(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
looks_latin1(const unsigned char *buf, size_t nbytes, unicodechar *ubuf, size_t *ulen)
{
size_t i;

Expand All @@ -290,7 +290,7 @@ looks_latin1(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ule
}

private int
looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
looks_extended(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
size_t *ulen)
{
size_t i;
Expand Down Expand Up @@ -321,11 +321,11 @@ looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
* ubuf must be big enough!
*/
protected int
file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
file_looks_utf8(const unsigned char *buf, size_t nbytes, unicodechar *ubuf, size_t *ulen)
{
size_t i;
int n;
unichar c;
unicodechar c;
int gotone = 0, ctrl = 0;

if (ubuf)
Expand Down Expand Up @@ -392,7 +392,7 @@ file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *
* rest of the text.
*/
private int
looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
size_t *ulen)
{
if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
Expand All @@ -402,7 +402,7 @@ looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
}

private int
looks_utf7(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
looks_utf7(const unsigned char *buf, size_t nbytes, unicodechar *ubuf, size_t *ulen)
{
if (nbytes > 4 && buf[0] == '+' && buf[1] == '/' && buf[2] == 'v')
switch (buf[3]) {
Expand All @@ -421,7 +421,7 @@ looks_utf7(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
}

private int
looks_ucs16(const unsigned char *bf, size_t nbytes, unichar *ubf,
looks_ucs16(const unsigned char *bf, size_t nbytes, unicodechar *ubf,
size_t *ulen)
{
int bigend;
Expand All @@ -444,10 +444,10 @@ looks_ucs16(const unsigned char *bf, size_t nbytes, unichar *ubf,

if (bigend)
ubf[(*ulen)++] = bf[i + 1]
| (CAST(unichar, bf[i]) << 8);
| (CAST(unicodechar, bf[i]) << 8);
else
ubf[(*ulen)++] = bf[i]
| (CAST(unichar, bf[i + 1]) << 8);
| (CAST(unicodechar, bf[i + 1]) << 8);

if (ubf[*ulen - 1] == 0xfffe)
return 0;
Expand All @@ -460,7 +460,7 @@ looks_ucs16(const unsigned char *bf, size_t nbytes, unichar *ubf,
}

private int
looks_ucs32(const unsigned char *bf, size_t nbytes, unichar *ubf,
looks_ucs32(const unsigned char *bf, size_t nbytes, unicodechar *ubf,
size_t *ulen)
{
int bigend;
Expand All @@ -482,15 +482,15 @@ looks_ucs32(const unsigned char *bf, size_t nbytes, unichar *ubf,
/* XXX fix to properly handle chars > 65536 */

if (bigend)
ubf[(*ulen)++] = CAST(unichar, bf[i + 3])
| (CAST(unichar, bf[i + 2]) << 8)
| (CAST(unichar, bf[i + 1]) << 16)
| (CAST(unichar, bf[i]) << 24);
ubf[(*ulen)++] = CAST(unicodechar, bf[i + 3])
| (CAST(unicodechar, bf[i + 2]) << 8)
| (CAST(unicodechar, bf[i + 1]) << 16)
| (CAST(unicodechar, bf[i]) << 24);
else
ubf[(*ulen)++] = CAST(unichar, bf[i + 0])
| (CAST(unichar, bf[i + 1]) << 8)
| (CAST(unichar, bf[i + 2]) << 16)
| (CAST(unichar, bf[i + 3]) << 24);
ubf[(*ulen)++] = CAST(unicodechar, bf[i + 0])
| (CAST(unicodechar, bf[i + 1]) << 8)
| (CAST(unicodechar, bf[i + 2]) << 16)
| (CAST(unicodechar, bf[i + 3]) << 24);

if (ubf[*ulen - 1] == 0xfffe)
return 0;
Expand Down
8 changes: 4 additions & 4 deletions ext/fileinfo/libmagic/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ struct magic_set {
};

/* Type for Unicode characters */
typedef unsigned long unichar;
typedef unsigned long unicodechar;

#define FILE_T_LOCAL 1
#define FILE_T_WINDOWS 2
Expand All @@ -464,9 +464,9 @@ protected int file_zmagic(struct magic_set *, const struct buffer *,
protected int file_ascmagic(struct magic_set *, const struct buffer *,
int);
protected int file_ascmagic_with_encoding(struct magic_set *,
const struct buffer *, unichar *, size_t, const char *, const char *, int);
const struct buffer *, unicodechar *, size_t, const char *, const char *, int);
protected int file_encoding(struct magic_set *, const struct buffer *,
unichar **, size_t *, const char **, const char **, const char **);
unicodechar **, size_t *, const char **, const char **, const char **);
protected int file_is_json(struct magic_set *, const struct buffer *);
protected int file_is_tar(struct magic_set *, const struct buffer *);
protected int file_softmagic(struct magic_set *, const struct buffer *,
Expand All @@ -488,7 +488,7 @@ protected size_t file_mbswidth(const char *);
protected const char *file_getbuffer(struct magic_set *);
protected ssize_t sread(int, void *, size_t, int);
protected int file_check_mem(struct magic_set *, unsigned int);
protected int file_looks_utf8(const unsigned char *, size_t, unichar *,
protected int file_looks_utf8(const unsigned char *, size_t, unicodechar *,
size_t *);
protected size_t file_pstring_length_size(const struct magic *);
protected size_t file_pstring_get_length(const struct magic *, const char *);
Expand Down