Skip to content

Commit dc91fbf

Browse files
committed
fileinfo build fix proposal for haiku.
Haiku already defines a unichar type and different than the fileinfo's anyway.
1 parent 90330a4 commit dc91fbf

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

ext/fileinfo/libmagic/ascmagic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ FILE_RCSID("@(#)$File: ascmagic.c,v 1.104 2019/05/07 02:27:11 christos Exp $")
5151
#define ISSPC(x) ((x) == ' ' || (x) == '\t' || (x) == '\r' || (x) == '\n' \
5252
|| (x) == 0x85 || (x) == '\f')
5353

54-
private unsigned char *encode_utf8(unsigned char *, size_t, unichar *, size_t);
54+
private unsigned char *encode_utf8(unsigned char *, size_t, unicodechar *, size_t);
5555
private size_t trim_nuls(const unsigned char *, size_t);
5656

5757
/*
@@ -70,7 +70,7 @@ trim_nuls(const unsigned char *buf, size_t nbytes)
7070
protected int
7171
file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)
7272
{
73-
unichar *ubuf = NULL;
73+
unicodechar *ubuf = NULL;
7474
size_t ulen = 0;
7575
int rv = 1;
7676
struct buffer bb;
@@ -103,7 +103,7 @@ file_ascmagic(struct magic_set *ms, const struct buffer *b, int text)
103103

104104
protected int
105105
file_ascmagic_with_encoding(struct magic_set *ms,
106-
const struct buffer *b, unichar *ubuf, size_t ulen, const char *code,
106+
const struct buffer *b, unicodechar *ubuf, size_t ulen, const char *code,
107107
const char *type, int text)
108108
{
109109
struct buffer bb;
@@ -338,7 +338,7 @@ file_ascmagic_with_encoding(struct magic_set *ms,
338338
* after end of string, or NULL if an invalid character is found.
339339
*/
340340
private unsigned char *
341-
encode_utf8(unsigned char *buf, size_t len, unichar *ubuf, size_t ulen)
341+
encode_utf8(unsigned char *buf, size_t len, unicodechar *ubuf, size_t ulen)
342342
{
343343
size_t i;
344344
unsigned char *end = buf + len;

ext/fileinfo/libmagic/encoding.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ FILE_RCSID("@(#)$File: encoding.c,v 1.20 2019/04/15 16:48:41 christos Exp $")
4444
#include <stdlib.h>
4545

4646

47-
private int looks_ascii(const unsigned char *, size_t, unichar *, size_t *);
48-
private int looks_utf8_with_BOM(const unsigned char *, size_t, unichar *,
47+
private int looks_ascii(const unsigned char *, size_t, unicodechar *, size_t *);
48+
private int looks_utf8_with_BOM(const unsigned char *, size_t, unicodechar *,
4949
size_t *);
50-
private int looks_utf7(const unsigned char *, size_t, unichar *, size_t *);
51-
private int looks_ucs16(const unsigned char *, size_t, unichar *, size_t *);
52-
private int looks_ucs32(const unsigned char *, size_t, unichar *, size_t *);
53-
private int looks_latin1(const unsigned char *, size_t, unichar *, size_t *);
54-
private int looks_extended(const unsigned char *, size_t, unichar *, size_t *);
50+
private int looks_utf7(const unsigned char *, size_t, unicodechar *, size_t *);
51+
private int looks_ucs16(const unsigned char *, size_t, unicodechar *, size_t *);
52+
private int looks_ucs32(const unsigned char *, size_t, unicodechar *, size_t *);
53+
private int looks_latin1(const unsigned char *, size_t, unicodechar *, size_t *);
54+
private int looks_extended(const unsigned char *, size_t, unicodechar *, size_t *);
5555
private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
5656

5757
#ifdef DEBUG_ENCODING
@@ -63,19 +63,19 @@ private void from_ebcdic(const unsigned char *, size_t, unsigned char *);
6363
/*
6464
* Try to determine whether text is in some character code we can
6565
* identify. Each of these tests, if it succeeds, will leave
66-
* the text converted into one-unichar-per-character Unicode in
66+
* the text converted into one-unicodechar-per-character Unicode in
6767
* ubuf, and the number of characters converted in ulen.
6868
*/
6969
protected int
70-
file_encoding(struct magic_set *ms, const struct buffer *b, unichar **ubuf,
70+
file_encoding(struct magic_set *ms, const struct buffer *b, unicodechar **ubuf,
7171
size_t *ulen, const char **code, const char **code_mime, const char **type)
7272
{
7373
const unsigned char *buf = CAST(const unsigned char *, b->fbuf);
7474
size_t nbytes = b->flen;
7575
size_t mlen;
7676
int rv = 1, ucs_type;
7777
unsigned char *nbuf = NULL;
78-
unichar *udefbuf;
78+
unicodechar *udefbuf;
7979
size_t udeflen;
8080

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

9191
mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
92-
if ((*ubuf = CAST(unichar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
92+
if ((*ubuf = CAST(unicodechar *, ecalloc(CAST(size_t, 1), mlen))) == NULL) {
9393
file_oomem(ms, mlen);
9494
goto done;
9595
}
@@ -251,7 +251,7 @@ private char text_chars[256] = {
251251
};
252252

253253
private int
254-
looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
254+
looks_ascii(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
255255
size_t *ulen)
256256
{
257257
size_t i;
@@ -271,7 +271,7 @@ looks_ascii(const unsigned char *buf, size_t nbytes, unichar *ubuf,
271271
}
272272

273273
private int
274-
looks_latin1(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
274+
looks_latin1(const unsigned char *buf, size_t nbytes, unicodechar *ubuf, size_t *ulen)
275275
{
276276
size_t i;
277277

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

292292
private int
293-
looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
293+
looks_extended(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
294294
size_t *ulen)
295295
{
296296
size_t i;
@@ -321,11 +321,11 @@ looks_extended(const unsigned char *buf, size_t nbytes, unichar *ubuf,
321321
* ubuf must be big enough!
322322
*/
323323
protected int
324-
file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *ulen)
324+
file_looks_utf8(const unsigned char *buf, size_t nbytes, unicodechar *ubuf, size_t *ulen)
325325
{
326326
size_t i;
327327
int n;
328-
unichar c;
328+
unicodechar c;
329329
int gotone = 0, ctrl = 0;
330330

331331
if (ubuf)
@@ -392,7 +392,7 @@ file_looks_utf8(const unsigned char *buf, size_t nbytes, unichar *ubuf, size_t *
392392
* rest of the text.
393393
*/
394394
private int
395-
looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
395+
looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unicodechar *ubuf,
396396
size_t *ulen)
397397
{
398398
if (nbytes > 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf)
@@ -402,7 +402,7 @@ looks_utf8_with_BOM(const unsigned char *buf, size_t nbytes, unichar *ubuf,
402402
}
403403

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

423423
private int
424-
looks_ucs16(const unsigned char *bf, size_t nbytes, unichar *ubf,
424+
looks_ucs16(const unsigned char *bf, size_t nbytes, unicodechar *ubf,
425425
size_t *ulen)
426426
{
427427
int bigend;
@@ -444,10 +444,10 @@ looks_ucs16(const unsigned char *bf, size_t nbytes, unichar *ubf,
444444

445445
if (bigend)
446446
ubf[(*ulen)++] = bf[i + 1]
447-
| (CAST(unichar, bf[i]) << 8);
447+
| (CAST(unicodechar, bf[i]) << 8);
448448
else
449449
ubf[(*ulen)++] = bf[i]
450-
| (CAST(unichar, bf[i + 1]) << 8);
450+
| (CAST(unicodechar, bf[i + 1]) << 8);
451451

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

462462
private int
463-
looks_ucs32(const unsigned char *bf, size_t nbytes, unichar *ubf,
463+
looks_ucs32(const unsigned char *bf, size_t nbytes, unicodechar *ubf,
464464
size_t *ulen)
465465
{
466466
int bigend;
@@ -482,15 +482,15 @@ looks_ucs32(const unsigned char *bf, size_t nbytes, unichar *ubf,
482482
/* XXX fix to properly handle chars > 65536 */
483483

484484
if (bigend)
485-
ubf[(*ulen)++] = CAST(unichar, bf[i + 3])
486-
| (CAST(unichar, bf[i + 2]) << 8)
487-
| (CAST(unichar, bf[i + 1]) << 16)
488-
| (CAST(unichar, bf[i]) << 24);
485+
ubf[(*ulen)++] = CAST(unicodechar, bf[i + 3])
486+
| (CAST(unicodechar, bf[i + 2]) << 8)
487+
| (CAST(unicodechar, bf[i + 1]) << 16)
488+
| (CAST(unicodechar, bf[i]) << 24);
489489
else
490-
ubf[(*ulen)++] = CAST(unichar, bf[i + 0])
491-
| (CAST(unichar, bf[i + 1]) << 8)
492-
| (CAST(unichar, bf[i + 2]) << 16)
493-
| (CAST(unichar, bf[i + 3]) << 24);
490+
ubf[(*ulen)++] = CAST(unicodechar, bf[i + 0])
491+
| (CAST(unicodechar, bf[i + 1]) << 8)
492+
| (CAST(unicodechar, bf[i + 2]) << 16)
493+
| (CAST(unicodechar, bf[i + 3]) << 24);
494494

495495
if (ubf[*ulen - 1] == 0xfffe)
496496
return 0;

ext/fileinfo/libmagic/file.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ struct magic_set {
439439
};
440440

441441
/* Type for Unicode characters */
442-
typedef unsigned long unichar;
442+
typedef unsigned long unicodechar;
443443

444444
#define FILE_T_LOCAL 1
445445
#define FILE_T_WINDOWS 2
@@ -464,9 +464,9 @@ protected int file_zmagic(struct magic_set *, const struct buffer *,
464464
protected int file_ascmagic(struct magic_set *, const struct buffer *,
465465
int);
466466
protected int file_ascmagic_with_encoding(struct magic_set *,
467-
const struct buffer *, unichar *, size_t, const char *, const char *, int);
467+
const struct buffer *, unicodechar *, size_t, const char *, const char *, int);
468468
protected int file_encoding(struct magic_set *, const struct buffer *,
469-
unichar **, size_t *, const char **, const char **, const char **);
469+
unicodechar **, size_t *, const char **, const char **, const char **);
470470
protected int file_is_json(struct magic_set *, const struct buffer *);
471471
protected int file_is_tar(struct magic_set *, const struct buffer *);
472472
protected int file_softmagic(struct magic_set *, const struct buffer *,
@@ -488,7 +488,7 @@ protected size_t file_mbswidth(const char *);
488488
protected const char *file_getbuffer(struct magic_set *);
489489
protected ssize_t sread(int, void *, size_t, int);
490490
protected int file_check_mem(struct magic_set *, unsigned int);
491-
protected int file_looks_utf8(const unsigned char *, size_t, unichar *,
491+
protected int file_looks_utf8(const unsigned char *, size_t, unicodechar *,
492492
size_t *);
493493
protected size_t file_pstring_length_size(const struct magic *);
494494
protected size_t file_pstring_get_length(const struct magic *, const char *);

0 commit comments

Comments
 (0)