Commit 07c76b66 authored by Guillem Jover's avatar Guillem Jover

Do not use legacy BSD u_* types

Some systems do not have these types available, and they are simply
convenience aliases. Instead use the expanded versions which are more
portable.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=101192
parent e4475738
......@@ -33,7 +33,7 @@
#ifndef _NETINET_IP_ICMP_H_
#define _NETINET_IP_ICMP_H_
#include <sys/types.h> /* u_int32_t, u_char */
#include <sys/types.h> /* uint32_t */
#include <netinet/in.h> /* in_addr */
#include <netinet/in_systm.h> /* n_short */
#include <netinet/ip.h> /* idi_ip */
......@@ -47,19 +47,19 @@
* Internal of an ICMP Router Advertisement
*/
struct icmp_ra_addr {
u_int32_t ira_addr;
u_int32_t ira_preference;
uint32_t ira_addr;
uint32_t ira_preference;
};
/*
* Structure of an icmp header.
*/
struct icmp {
u_char icmp_type; /* type of message, see below */
u_char icmp_code; /* type sub code */
u_short icmp_cksum; /* ones complement cksum of struct */
unsigned char icmp_type; /* type of message, see below */
unsigned char icmp_code; /* type sub code */
unsigned short icmp_cksum; /* ones complement cksum of struct */
union {
u_char ih_pptr; /* ICMP_PARAMPROB */
unsigned char ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
n_short icd_id;
......@@ -74,9 +74,9 @@ struct icmp {
} ih_pmtu;
struct ih_rtradv {
u_char irt_num_addrs;
u_char irt_wpa;
u_int16_t irt_lifetime;
unsigned char irt_num_addrs;
unsigned char irt_wpa;
uint16_t irt_lifetime;
} ih_rtradv;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
......@@ -100,7 +100,7 @@ struct icmp {
/* options and then 64 bits of data */
} id_ip;
struct icmp_ra_addr id_radv;
u_int32_t id_mask;
uint32_t id_mask;
char id_data[1];
} icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime
......
......@@ -49,7 +49,7 @@
__BEGIN_DECLS
uint32_t arc4random(void);
void arc4random_stir(void);
void arc4random_addrandom(u_char *dat, int datlen);
void arc4random_addrandom(unsigned char *dat, int datlen);
void arc4random_buf(void *_buf, size_t n);
uint32_t arc4random_uniform(uint32_t upper_bound);
......
......@@ -59,7 +59,7 @@ static struct _rs {
/* Maybe be preserved in fork children, if _rs_allocate() decides. */
static struct _rsx {
chacha_ctx rs_chacha; /* chacha context for random keystream */
u_char rs_buf[RSBUFSZ]; /* keystream blocks */
unsigned char rs_buf[RSBUFSZ]; /* keystream blocks */
} *rsx;
static inline int _rs_allocate(struct _rs **, struct _rsx **);
......@@ -67,7 +67,7 @@ static inline void _rs_forkdetect(void);
#include "arc4random.h"
static inline void
_rs_init(u_char *buf, size_t n)
_rs_init(unsigned char *buf, size_t n)
{
if (n < KEYSZ + IVSZ)
return;
......@@ -82,7 +82,7 @@ _rs_init(u_char *buf, size_t n)
}
static inline void
_rs_rekey(u_char *dat, size_t datlen)
_rs_rekey(unsigned char *dat, size_t datlen)
{
#ifndef KEYSTREAM_ONLY
memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
......@@ -107,7 +107,7 @@ _rs_rekey(u_char *dat, size_t datlen)
static void
_rs_stir(void)
{
u_char rnd[KEYSZ + IVSZ];
unsigned char rnd[KEYSZ + IVSZ];
if (getentropy(rnd, sizeof rnd) == -1)
_getentropy_fail();
......@@ -140,8 +140,8 @@ _rs_stir_if_needed(size_t len)
static inline void
_rs_random_buf(void *_buf, size_t n)
{
u_char *buf = (u_char *)_buf;
u_char *keystream;
unsigned char *buf = (unsigned char *)_buf;
unsigned char *keystream;
size_t m;
_rs_stir_if_needed(n);
......@@ -164,7 +164,7 @@ _rs_random_buf(void *_buf, size_t n)
static inline void
_rs_random_u32(uint32_t *val)
{
u_char *keystream;
unsigned char *keystream;
_rs_stir_if_needed(sizeof(*val));
if (rs->rs_have < sizeof(*val))
......@@ -184,7 +184,7 @@ arc4random_stir(void)
}
void
arc4random_addrandom(u_char *dat, int datlen)
arc4random_addrandom(unsigned char *dat, int datlen)
{
_ARC4_LOCK();
_rs_stir_if_needed(datlen);
......
......@@ -92,7 +92,7 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
u8 *ctarget = NULL;
u8 tmp[64];
u_int i;
unsigned int i;
if (!bytes) return;
......
......@@ -30,7 +30,7 @@
* Derived from lib/libc/gen/arc4random.c from FreeBSD.
*/
static size_t
getentropy_sysctl(u_char *buf, size_t size)
getentropy_sysctl(unsigned char *buf, size_t size)
{
int mib[2];
size_t len, done;
......
......@@ -51,7 +51,7 @@ char *
HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
{
struct stat sb;
u_char buffer[BUFSIZ];
unsigned char buffer[BUFSIZ];
HASH_CTX ctx;
int fd, save_errno;
ssize_t nr;
......@@ -92,7 +92,7 @@ HASHFile(const char *filename, char *buf)
}
char *
HASHData(const u_char *data, size_t len, char *buf)
HASHData(const unsigned char *data, size_t len, char *buf)
{
HASH_CTX ctx;
......
......@@ -39,7 +39,7 @@ __FBSDID("$FreeBSD: src/lib/libc/net/inet_net_pton.c,v 1.9 2003/09/15 23:38:06 f
# define SPRINTF(x) ((size_t)sprintf x)
#endif
static int inet_net_pton_ipv4(const char *src, u_char *dst, size_t size);
static int inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size);
/*
* static int
......@@ -83,13 +83,13 @@ inet_net_pton(int af, const char *src, void *dst, size_t size)
* Paul Vixie (ISC), June 1996
*/
static int
inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
inet_net_pton_ipv4(const char *src, unsigned char *dst, size_t size)
{
static const char
xdigits[] = "0123456789abcdef",
digits[] = "0123456789";
int n, ch, tmp, dirty, bits;
const u_char *odst = dst;
const unsigned char *odst = dst;
ch = *src++;
if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
......@@ -130,7 +130,7 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
isascii(ch) && isdigit(ch));
if (size-- <= 0)
goto emsgsize;
*dst++ = (u_char) tmp;
*dst++ = (unsigned char) tmp;
if (ch == '\0' || ch == '/')
break;
if (ch != '.')
......
......@@ -56,13 +56,13 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
static void setup(u_char *, u_char *, size_t, size_t,
static void setup(unsigned char *, unsigned char *, size_t, size_t,
int (*)(const void *, const void *));
static void insertionsort(u_char *, size_t, size_t,
static void insertionsort(unsigned char *, size_t, size_t,
int (*)(const void *, const void *));
#define ISIZE sizeof(int)
#define PSIZE sizeof(u_char *)
#define PSIZE sizeof(unsigned char *)
#define ICOPY_LIST(src, dst, last) \
do \
*(int*)dst = *(int*)src, src += ISIZE, dst += ISIZE; \
......@@ -87,9 +87,10 @@ static void insertionsort(u_char *, size_t, size_t,
* boundaries.
*/
/* Assumption: PSIZE is a power of 2. */
#define EVAL(p) (u_char **) \
((u_char *)0 + \
(((u_char *)p + PSIZE - 1 - (u_char *) 0) & ~(PSIZE - 1)))
#define EVAL(p) (unsigned char **) \
((unsigned char *)0 + \
(((unsigned char *)p + PSIZE - 1 - \
(unsigned char *)0) & ~(PSIZE - 1)))
/*
* Arguments are as for qsort.
......@@ -101,8 +102,8 @@ mergesort(void *base, size_t nmemb, size_t size,
size_t i;
int sense;
int big, iflag;
u_char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
u_char *list2, *list1, *p2, *p, *last, **p1;
unsigned char *f1, *f2, *t, *b, *tp2, *q, *l1, *l2;
unsigned char *list2, *list1, *p2, *p, *last, **p1;
if (size < PSIZE / 2) { /* Pointers must fit into 2 * size. */
errno = EINVAL;
......@@ -256,16 +257,16 @@ COPY: b = t;
* is defined. Otherwise simple pairwise merging is used.)
*/
static void
setup(u_char *list1, u_char *list2, size_t n, size_t size,
setup(unsigned char *list1, unsigned char *list2, size_t n, size_t size,
int (*cmp)(const void *, const void *))
{
int i, length, size2, tmp, sense;
u_char *f1, *f2, *s, *l2, *last, *p2;
unsigned char *f1, *f2, *s, *l2, *last, *p2;
size2 = size*2;
if (n <= 5) {
insertionsort(list1, n, size, cmp);
*EVAL(list2) = (u_char*) list2 + n*size;
*EVAL(list2) = (unsigned char*) list2 + n*size;
return;
}
/*
......@@ -328,10 +329,10 @@ setup(u_char *list1, u_char *list2, size_t n, size_t size,
* last 4 elements.
*/
static void
insertionsort(u_char *a, size_t n, size_t size,
insertionsort(unsigned char *a, size_t n, size_t size,
int (*cmp)(const void *, const void *))
{
u_char *ai, *s, *t, *u, tmp;
unsigned char *ai, *s, *t, *u, tmp;
int i;
for (ai = a+size; --n >= 1; ai += size)
......
......@@ -117,7 +117,7 @@ __aout_fdnlist(int fd, struct nlist *list)
struct nlist *p, *symtab;
caddr_t strtab, a_out_mmap;
off_t stroff, symoff;
u_long symsize;
unsigned long symsize;
int nent;
struct exec * exec;
struct stat st;
......
......@@ -59,14 +59,14 @@ __RCSID("$NetBSD: radixsort.c,v 1.18 2009/08/21 20:49:50 dsl Exp $");
#include <errno.h>
typedef struct {
const u_char **sa;
const unsigned char **sa;
int sn, si;
} stack;
static inline void simplesort(const u_char **, int, int, const u_char *, u_int);
static void r_sort_a(const u_char **, int, int, const u_char *, u_int);
static void r_sort_b(const u_char **,
const u_char **, int, int, const u_char *, u_int);
static inline void simplesort(const unsigned char **, int, int, const unsigned char *, unsigned int);
static void r_sort_a(const unsigned char **, int, int, const unsigned char *, unsigned int);
static void r_sort_b(const unsigned char **,
const unsigned char **, int, int, const unsigned char *, unsigned int);
#define THRESHOLD 20 /* Divert to simplesort(). */
#define SIZE 512 /* Default stack size. */
......@@ -91,11 +91,12 @@ static void r_sort_b(const u_char **,
}
int
radixsort(const u_char **a, int n, const u_char *tab, u_int endch)
radixsort(const unsigned char **a, int n, const unsigned char *tab,
unsigned int endch)
{
const u_char *tr;
u_int c;
u_char tr0[256];
const unsigned char *tr;
unsigned int c;
unsigned char tr0[256];
SETUP;
r_sort_a(a, n, 0, tr, endch);
......@@ -103,11 +104,12 @@ radixsort(const u_char **a, int n, const u_char *tab, u_int endch)
}
int
sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
sradixsort(const unsigned char **a, int n, const unsigned char *tab,
unsigned int endch)
{
const u_char *tr, **ta;
u_int c;
u_char tr0[256];
const unsigned char *tr, **ta;
unsigned int c;
unsigned char tr0[256];
if (a == NULL) {
errno = EFAULT;
......@@ -134,14 +136,15 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
/* Unstable, in-place sort. */
static void
r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
r_sort_a(const unsigned char **a, int n, int i, const unsigned char *tr,
unsigned int endch)
{
static u_int count[256], nc, bmin;
u_int c;
const u_char **ak, *r;
static unsigned int count[256], nc, bmin;
unsigned int c;
const unsigned char **ak, *r;
stack s[SIZE], *sp, *sp0, *sp1, temp;
u_int *cp, bigc;
const u_char **an, *t, **aj, **top[256];
unsigned int *cp, bigc;
const unsigned char **an, *t, **aj, **top[256];
/* Set up stack. */
sp = s;
......@@ -176,7 +179,7 @@ r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
* character at position i, move on to the next
* character.
*/
if (nc == 1 && count[bmin] == (u_int)n) {
if (nc == 1 && count[bmin] == (unsigned int)n) {
push(a, n, i+1);
nc = count[bmin] = 0;
continue;
......@@ -232,15 +235,15 @@ r_sort_a(const u_char **a, int n, int i, const u_char *tr, u_int endch)
/* Stable sort, requiring additional memory. */
static void
r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr,
u_int endch)
r_sort_b(const unsigned char **a, const unsigned char **ta, int n, int i,
const unsigned char *tr, unsigned int endch)
{
static u_int count[256], nc, bmin;
u_int c;
const u_char **ak, **ai;
static unsigned int count[256], nc, bmin;
unsigned int c;
const unsigned char **ak, **ai;
stack s[512], *sp, *sp0, *sp1, temp;
const u_char **top[256];
u_int *cp, bigc;
const unsigned char **top[256];
unsigned int *cp, bigc;
sp = s;
push(a, n, i);
......@@ -302,10 +305,11 @@ r_sort_b(const u_char **a, const u_char **ta, int n, int i, const u_char *tr,
/* insertion sort */
static inline void
simplesort(const u_char **a, int n, int b, const u_char *tr, u_int endch)
simplesort(const unsigned char **a, int n, int b, const unsigned char *tr,
unsigned int endch)
{
u_char ch;
const u_char **ak, **ai, *s, *t;
unsigned char ch;
const unsigned char **ak, **ai, *s, *t;
for (ak = a+1; --n >= 1; ak++)
for (ai = ak; ai > a; ai--) {
......
......@@ -45,8 +45,11 @@
#define S_HTTP 0x080 /* %HEXHEX escape */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f'))
#define isoctal(c) \
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
#define ishex(c) \
((((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '9') || \
(((unsigned char)(c)) >= 'a' && ((unsigned char)(c)) <= 'f'))
/*
* unvis - decode characters previously encoded by vis
......
......@@ -35,17 +35,20 @@
#include <stdio.h>
#include <vis.h>
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
#define isoctal(c) \
(((unsigned char)(c)) >= '0' && ((unsigned char)(c)) <= '7')
#define isvisible(c) \
(((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
(((unsigned int)(c) <= UCHAR_MAX && \
isascii((unsigned char)(c)) && \
(((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \
(flag & VIS_GLOB) == 0) && isgraph((u_char)(c))) || \
(flag & VIS_GLOB) == 0) && \
isgraph((unsigned char)(c))) || \
((flag & VIS_SP) == 0 && (c) == ' ') || \
((flag & VIS_TAB) == 0 && (c) == '\t') || \
((flag & VIS_NL) == 0 && (c) == '\n') || \
((flag & VIS_SAFE) && ((c) == '\b' || \
(c) == '\007' || (c) == '\r' || \
isgraph((u_char)(c)))))
isgraph((unsigned char)(c)))))
/*
* vis - visually encode characters
......@@ -131,9 +134,9 @@ vis(char *dst, int c, int flag, int nextc)
}
if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) {
*dst++ = '\\';
*dst++ = ((u_char)c >> 6 & 07) + '0';
*dst++ = ((u_char)c >> 3 & 07) + '0';
*dst++ = ((u_char)c & 07) + '0';
*dst++ = ((unsigned char)c >> 6 & 07) + '0';
*dst++ = ((unsigned char)c >> 3 & 07) + '0';
*dst++ = ((unsigned char)c & 07) + '0';
goto done;
}
if ((flag & VIS_NOSLASH) == 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment