mirror of
https://github.com/pine64/bl_iot_sdk.git
synced 2024-07-08 05:59:17 +00:00
clean components/ whitespace issues
image_conf, make_scripts_riscv - Delete trailing spaces. Change tabs to 4 space multiples. .c and .h get tabs expanded to four spaces for consistency, traliing whitespace whacked. Makefiles do NOT get tabs changed.
This commit is contained in:
parent
e82b9d746d
commit
3bc544d9f3
0
components/bl602/bl602/evb/src/compat_attribute.h
Executable file → Normal file
0
components/bl602/bl602/evb/src/compat_attribute.h
Executable file → Normal file
896
components/bl602/bl602/evb/src/debug.c
Executable file → Normal file
896
components/bl602/bl602/evb/src/debug.c
Executable file → Normal file
|
@ -34,171 +34,171 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
//#define CHAR_BIT 8
|
//#define CHAR_BIT 8
|
||||||
//FIXME no ugly declare
|
//FIXME no ugly declare
|
||||||
extern int bl_uart_data_send(uint8_t id, uint8_t data);
|
extern int bl_uart_data_send(uint8_t id, uint8_t data);
|
||||||
|
|
||||||
enum flag {
|
enum flag {
|
||||||
FL_ZERO = 0x01, /* Zero modifier */
|
FL_ZERO = 0x01, /* Zero modifier */
|
||||||
FL_MINUS = 0x02, /* Minus modifier */
|
FL_MINUS = 0x02, /* Minus modifier */
|
||||||
FL_PLUS = 0x04, /* Plus modifier */
|
FL_PLUS = 0x04, /* Plus modifier */
|
||||||
FL_TICK = 0x08, /* ' modifier */
|
FL_TICK = 0x08, /* ' modifier */
|
||||||
FL_SPACE = 0x10, /* Space modifier */
|
FL_SPACE = 0x10, /* Space modifier */
|
||||||
FL_HASH = 0x20, /* # modifier */
|
FL_HASH = 0x20, /* # modifier */
|
||||||
FL_SIGNED = 0x40, /* Number is signed */
|
FL_SIGNED = 0x40, /* Number is signed */
|
||||||
FL_UPPER = 0x80 /* Upper case digits */
|
FL_UPPER = 0x80 /* Upper case digits */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* These may have to be adjusted on certain implementations */
|
/* These may have to be adjusted on certain implementations */
|
||||||
enum ranks {
|
enum ranks {
|
||||||
rank_char = -2,
|
rank_char = -2,
|
||||||
rank_short = -1,
|
rank_short = -1,
|
||||||
rank_int = 0,
|
rank_int = 0,
|
||||||
rank_long = 1,
|
rank_long = 1,
|
||||||
rank_longlong = 2
|
rank_longlong = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MIN_RANK rank_char
|
#define MIN_RANK rank_char
|
||||||
#define MAX_RANK rank_longlong
|
#define MAX_RANK rank_longlong
|
||||||
|
|
||||||
#define INTMAX_RANK rank_longlong
|
#define INTMAX_RANK rank_longlong
|
||||||
#define SIZE_T_RANK rank_long
|
#define SIZE_T_RANK rank_long
|
||||||
#define PTRDIFF_T_RANK rank_long
|
#define PTRDIFF_T_RANK rank_long
|
||||||
|
|
||||||
#define EMIT(x) { if (o < n) { *q++ = (x); } o++; }
|
#define EMIT(x) { if (o < n) { *q++ = (x); } o++; }
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
format_int(char *q, size_t n, uintmax_t val, unsigned int flags,
|
format_int(char *q, size_t n, uintmax_t val, unsigned int flags,
|
||||||
int base, int width, int prec)
|
int base, int width, int prec)
|
||||||
{
|
{
|
||||||
char *qq;
|
char *qq;
|
||||||
size_t o = 0, oo;
|
size_t o = 0, oo;
|
||||||
static const char lcdigits[] = "0123456789abcdef";
|
static const char lcdigits[] = "0123456789abcdef";
|
||||||
static const char ucdigits[] = "0123456789ABCDEF";
|
static const char ucdigits[] = "0123456789ABCDEF";
|
||||||
const char *digits;
|
const char *digits;
|
||||||
uintmax_t tmpval;
|
uintmax_t tmpval;
|
||||||
int minus = 0;
|
int minus = 0;
|
||||||
int ndigits = 0, nchars;
|
int ndigits = 0, nchars;
|
||||||
int tickskip, b4tick;
|
int tickskip, b4tick;
|
||||||
|
|
||||||
/* Select type of digits */
|
/* Select type of digits */
|
||||||
digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
|
digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
|
||||||
|
|
||||||
/* If signed, separate out the minus */
|
/* If signed, separate out the minus */
|
||||||
if (flags & FL_SIGNED && (intmax_t) val < 0) {
|
if (flags & FL_SIGNED && (intmax_t) val < 0) {
|
||||||
minus = 1;
|
minus = 1;
|
||||||
val = (uintmax_t) (-(intmax_t) val);
|
val = (uintmax_t) (-(intmax_t) val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count the number of digits needed. This returns zero for 0. */
|
/* Count the number of digits needed. This returns zero for 0. */
|
||||||
tmpval = val;
|
tmpval = val;
|
||||||
while (tmpval) {
|
while (tmpval) {
|
||||||
tmpval /= base;
|
tmpval /= base;
|
||||||
ndigits++;
|
ndigits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust ndigits for size of output */
|
/* Adjust ndigits for size of output */
|
||||||
|
|
||||||
if (flags & FL_HASH && base == 8) {
|
if (flags & FL_HASH && base == 8) {
|
||||||
if (prec < ndigits + 1)
|
if (prec < ndigits + 1)
|
||||||
prec = ndigits + 1;
|
prec = ndigits + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ndigits < prec) {
|
if (ndigits < prec) {
|
||||||
ndigits = prec; /* Mandatory number padding */
|
ndigits = prec; /* Mandatory number padding */
|
||||||
} else if (val == 0) {
|
} else if (val == 0) {
|
||||||
ndigits = 1; /* Zero still requires space */
|
ndigits = 1; /* Zero still requires space */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For ', figure out what the skip should be */
|
/* For ', figure out what the skip should be */
|
||||||
if (flags & FL_TICK) {
|
if (flags & FL_TICK) {
|
||||||
tickskip = (base == 16) ? 4 : 3;
|
tickskip = (base == 16) ? 4 : 3;
|
||||||
} else {
|
} else {
|
||||||
tickskip = ndigits; /* No tick marks */
|
tickskip = ndigits; /* No tick marks */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tick marks aren't digits, but generated by the number converter */
|
/* Tick marks aren't digits, but generated by the number converter */
|
||||||
ndigits += (ndigits - 1) / tickskip;
|
ndigits += (ndigits - 1) / tickskip;
|
||||||
|
|
||||||
/* Now compute the number of nondigits */
|
/* Now compute the number of nondigits */
|
||||||
nchars = ndigits;
|
nchars = ndigits;
|
||||||
|
|
||||||
if (minus || (flags & (FL_PLUS | FL_SPACE)))
|
if (minus || (flags & (FL_PLUS | FL_SPACE)))
|
||||||
nchars++; /* Need space for sign */
|
nchars++; /* Need space for sign */
|
||||||
if ((flags & FL_HASH) && base == 16) {
|
if ((flags & FL_HASH) && base == 16) {
|
||||||
nchars += 2; /* Add 0x for hex */
|
nchars += 2; /* Add 0x for hex */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit early space padding */
|
/* Emit early space padding */
|
||||||
if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
|
if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
|
||||||
while (width > nchars) {
|
while (width > nchars) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit nondigits */
|
/* Emit nondigits */
|
||||||
if (minus) {
|
if (minus) {
|
||||||
EMIT('-');
|
EMIT('-');
|
||||||
} else if (flags & FL_PLUS) {
|
} else if (flags & FL_PLUS) {
|
||||||
EMIT('+');
|
EMIT('+');
|
||||||
} else if (flags & FL_SPACE) {
|
} else if (flags & FL_SPACE) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & FL_HASH) && base == 16) {
|
if ((flags & FL_HASH) && base == 16) {
|
||||||
EMIT('0');
|
EMIT('0');
|
||||||
EMIT((flags & FL_UPPER) ? 'X' : 'x');
|
EMIT((flags & FL_UPPER) ? 'X' : 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit zero padding */
|
/* Emit zero padding */
|
||||||
if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
|
if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
|
||||||
while (width > nchars) {
|
while (width > nchars) {
|
||||||
EMIT('0');
|
EMIT('0');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the number. This is done from right to left. */
|
/* Generate the number. This is done from right to left. */
|
||||||
q += ndigits; /* Advance the pointer to end of number */
|
q += ndigits; /* Advance the pointer to end of number */
|
||||||
o += ndigits;
|
o += ndigits;
|
||||||
qq = q;
|
qq = q;
|
||||||
oo = o; /* Temporary values */
|
oo = o; /* Temporary values */
|
||||||
|
|
||||||
b4tick = tickskip;
|
b4tick = tickskip;
|
||||||
while (ndigits > 0) {
|
while (ndigits > 0) {
|
||||||
if (!b4tick--) {
|
if (!b4tick--) {
|
||||||
qq--;
|
qq--;
|
||||||
oo--;
|
oo--;
|
||||||
ndigits--;
|
ndigits--;
|
||||||
if (oo < n)
|
if (oo < n)
|
||||||
*qq = '_';
|
*qq = '_';
|
||||||
b4tick = tickskip - 1;
|
b4tick = tickskip - 1;
|
||||||
}
|
}
|
||||||
qq--;
|
qq--;
|
||||||
oo--;
|
oo--;
|
||||||
ndigits--;
|
ndigits--;
|
||||||
if (oo < n)
|
if (oo < n)
|
||||||
*qq = digits[val % base];
|
*qq = digits[val % base];
|
||||||
val /= base;
|
val /= base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit late space padding */
|
/* Emit late space padding */
|
||||||
while ((flags & FL_MINUS) && width > nchars) {
|
while ((flags & FL_MINUS) && width > nchars) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ZEROPAD (1<<0) /* Pad with zero */
|
#define ZEROPAD (1<<0) /* Pad with zero */
|
||||||
#define SIGN (1<<1) /* Unsigned/signed long */
|
#define SIGN (1<<1) /* Unsigned/signed long */
|
||||||
#define PLUS (1<<2) /* Show plus */
|
#define PLUS (1<<2) /* Show plus */
|
||||||
#define SPACE (1<<3) /* Spacer */
|
#define SPACE (1<<3) /* Spacer */
|
||||||
#define LEFT (1<<4) /* Left justified */
|
#define LEFT (1<<4) /* Left justified */
|
||||||
#define HEX_PREP (1<<5) /* 0x */
|
#define HEX_PREP (1<<5) /* 0x */
|
||||||
#define UPPERCASE (1<<6) /* 'ABCDEF' */
|
#define UPPERCASE (1<<6) /* 'ABCDEF' */
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#define CVTBUFSIZE 80
|
#define CVTBUFSIZE 80
|
||||||
|
@ -295,9 +295,9 @@ char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf)
|
||||||
static void ee_bufcpy(char *d, char *s, int count);
|
static void ee_bufcpy(char *d, char *s, int count);
|
||||||
|
|
||||||
void ee_bufcpy(char *pd, char *ps, int count) {
|
void ee_bufcpy(char *pd, char *ps, int count) {
|
||||||
char *pe=ps+count;
|
char *pe=ps+count;
|
||||||
while (ps!=pe)
|
while (ps!=pe)
|
||||||
*pd++=*ps++;
|
*pd++=*ps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_float(double value, char *buffer, char fmt, int precision)
|
static void parse_float(double value, char *buffer, char fmt, int precision)
|
||||||
|
@ -442,7 +442,7 @@ static void cropzeros(char *buffer)
|
||||||
while (*buffer == '0') buffer--;
|
while (*buffer == '0') buffer--;
|
||||||
if (*buffer == '.') buffer--;
|
if (*buffer == '.') buffer--;
|
||||||
while (buffer!=stop)
|
while (buffer!=stop)
|
||||||
*++buffer=0;
|
*++buffer=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,332 +505,332 @@ static char *flt(char *str, double num, int size, int precision, char fmt, int f
|
||||||
/*use O0 preventing consuming more stack*/
|
/*use O0 preventing consuming more stack*/
|
||||||
int __attribute__((optimize("O1"))) vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
int __attribute__((optimize("O1"))) vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
const char *p = format;
|
const char *p = format;
|
||||||
char ch;
|
char ch;
|
||||||
char *q = buffer;
|
char *q = buffer;
|
||||||
size_t o = 0; /* Number of characters output */
|
size_t o = 0; /* Number of characters output */
|
||||||
uintmax_t val = 0;
|
uintmax_t val = 0;
|
||||||
int rank = rank_int; /* Default rank */
|
int rank = rank_int; /* Default rank */
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int prec = -1;
|
int prec = -1;
|
||||||
int base;
|
int base;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
enum {
|
enum {
|
||||||
st_normal, /* Ground state */
|
st_normal, /* Ground state */
|
||||||
st_flags, /* Special flags */
|
st_flags, /* Special flags */
|
||||||
st_width, /* Field width */
|
st_width, /* Field width */
|
||||||
st_prec, /* Field precision */
|
st_prec, /* Field precision */
|
||||||
st_modifiers /* Length or conversion modifiers */
|
st_modifiers /* Length or conversion modifiers */
|
||||||
} state = st_normal;
|
} state = st_normal;
|
||||||
const char *sarg; /* %s string argument */
|
const char *sarg; /* %s string argument */
|
||||||
char carg; /* %c char argument */
|
char carg; /* %c char argument */
|
||||||
int slen; /* String length */
|
int slen; /* String length */
|
||||||
|
|
||||||
while ((ch = *p++)) {
|
while ((ch = *p++)) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case st_normal:
|
case st_normal:
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
state = st_flags;
|
state = st_flags;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
rank = rank_int;
|
rank = rank_int;
|
||||||
width = 0;
|
width = 0;
|
||||||
prec = -1;
|
prec = -1;
|
||||||
} else {
|
} else {
|
||||||
EMIT(ch);
|
EMIT(ch);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_flags:
|
case st_flags:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '-':
|
case '-':
|
||||||
flags |= FL_MINUS;
|
flags |= FL_MINUS;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
flags |= FL_PLUS;
|
flags |= FL_PLUS;
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
flags |= FL_TICK;
|
flags |= FL_TICK;
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
flags |= FL_SPACE;
|
flags |= FL_SPACE;
|
||||||
break;
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
flags |= FL_HASH;
|
flags |= FL_HASH;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
flags |= FL_ZERO;
|
flags |= FL_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state = st_width;
|
state = st_width;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_width:
|
case st_width:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
width = width * 10 + (ch - '0');
|
width = width * 10 + (ch - '0');
|
||||||
} else if (ch == '*') {
|
} else if (ch == '*') {
|
||||||
width = va_arg(ap, int);
|
width = va_arg(ap, int);
|
||||||
if (width < 0) {
|
if (width < 0) {
|
||||||
width = -width;
|
width = -width;
|
||||||
flags |= FL_MINUS;
|
flags |= FL_MINUS;
|
||||||
}
|
}
|
||||||
} else if (ch == '.') {
|
} else if (ch == '.') {
|
||||||
prec = 0; /* Precision given */
|
prec = 0; /* Precision given */
|
||||||
state = st_prec;
|
state = st_prec;
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_prec:
|
case st_prec:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
prec = prec * 10 + (ch - '0');
|
prec = prec * 10 + (ch - '0');
|
||||||
} else if (ch == '*') {
|
} else if (ch == '*') {
|
||||||
prec = va_arg(ap, int);
|
prec = va_arg(ap, int);
|
||||||
if (prec < 0)
|
if (prec < 0)
|
||||||
prec = -1;
|
prec = -1;
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_modifiers:
|
case st_modifiers:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* Length modifiers - nonterminal sequences */
|
/* Length modifiers - nonterminal sequences */
|
||||||
case 'h':
|
case 'h':
|
||||||
rank--; /* Shorter rank */
|
rank--; /* Shorter rank */
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
rank++; /* Longer rank */
|
rank++; /* Longer rank */
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
rank = INTMAX_RANK;
|
rank = INTMAX_RANK;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
rank = SIZE_T_RANK;
|
rank = SIZE_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
rank = PTRDIFF_T_RANK;
|
rank = PTRDIFF_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'q':
|
case 'q':
|
||||||
rank += 2;
|
rank += 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Output modifiers - terminal sequences */
|
/* Output modifiers - terminal sequences */
|
||||||
|
|
||||||
/* Next state will be normal */
|
/* Next state will be normal */
|
||||||
state = st_normal;
|
state = st_normal;
|
||||||
|
|
||||||
/* Canonicalize rank */
|
/* Canonicalize rank */
|
||||||
if (rank < MIN_RANK)
|
if (rank < MIN_RANK)
|
||||||
rank = MIN_RANK;
|
rank = MIN_RANK;
|
||||||
else if (rank > MAX_RANK)
|
else if (rank > MAX_RANK)
|
||||||
rank = MAX_RANK;
|
rank = MAX_RANK;
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'P': /* Upper case pointer */
|
case 'P': /* Upper case pointer */
|
||||||
flags |= FL_UPPER;
|
flags |= FL_UPPER;
|
||||||
__attribute__ ((fallthrough));
|
__attribute__ ((fallthrough));
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'p': /* Pointer */
|
case 'p': /* Pointer */
|
||||||
base = 16;
|
base = 16;
|
||||||
prec = (CHAR_BIT*sizeof(void *)+3)/4;
|
prec = (CHAR_BIT*sizeof(void *)+3)/4;
|
||||||
flags |= FL_HASH;
|
flags |= FL_HASH;
|
||||||
val = (uintmax_t)(uintptr_t)
|
val = (uintmax_t)(uintptr_t)
|
||||||
va_arg(ap, void *);
|
va_arg(ap, void *);
|
||||||
goto is_integer;
|
goto is_integer;
|
||||||
|
|
||||||
case 'd': /* Signed decimal output */
|
case 'd': /* Signed decimal output */
|
||||||
case 'i':
|
case 'i':
|
||||||
base = 10;
|
base = 10;
|
||||||
flags |= FL_SIGNED;
|
flags |= FL_SIGNED;
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
/* Yes, all these casts are
|
/* Yes, all these casts are
|
||||||
needed... */
|
needed... */
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
(signed char)
|
(signed char)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
(signed short)
|
(signed short)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap, signed long);
|
va_arg(ap, signed long);
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap,
|
va_arg(ap,
|
||||||
signed long long);
|
signed long long);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
goto is_integer;
|
goto is_integer;
|
||||||
case 'o': /* Octal */
|
case 'o': /* Octal */
|
||||||
base = 8;
|
base = 8;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
case 'u': /* Unsigned decimal */
|
case 'u': /* Unsigned decimal */
|
||||||
base = 10;
|
base = 10;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
case 'X': /* Upper case hexadecimal */
|
case 'X': /* Upper case hexadecimal */
|
||||||
flags |= FL_UPPER;
|
flags |= FL_UPPER;
|
||||||
__attribute__ ((fallthrough));
|
__attribute__ ((fallthrough));
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'x': /* Hexadecimal */
|
case 'x': /* Hexadecimal */
|
||||||
base = 16;
|
base = 16;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
|
|
||||||
is_unsigned:
|
is_unsigned:
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
(unsigned char)
|
(unsigned char)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
(unsigned short)
|
(unsigned short)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
long);
|
long);
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
long long);
|
long long);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
is_integer:
|
is_integer:
|
||||||
sz = format_int(q, (o < n) ? n - o : 0,
|
sz = format_int(q, (o < n) ? n - o : 0,
|
||||||
val, flags, base,
|
val, flags, base,
|
||||||
width, prec);
|
width, prec);
|
||||||
q += sz;
|
q += sz;
|
||||||
o += sz;
|
o += sz;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* Character */
|
case 'c': /* Character */
|
||||||
carg = (char)va_arg(ap, int);
|
carg = (char)va_arg(ap, int);
|
||||||
sarg = &carg;
|
sarg = &carg;
|
||||||
slen = 1;
|
slen = 1;
|
||||||
goto is_string;
|
goto is_string;
|
||||||
case 's': /* String */
|
case 's': /* String */
|
||||||
sarg = va_arg(ap, const char *);
|
sarg = va_arg(ap, const char *);
|
||||||
sarg = sarg ? sarg : "(null)";
|
sarg = sarg ? sarg : "(null)";
|
||||||
slen = strlen(sarg);
|
slen = strlen(sarg);
|
||||||
goto is_string;
|
goto is_string;
|
||||||
|
|
||||||
is_string:
|
is_string:
|
||||||
{
|
{
|
||||||
char sch;
|
char sch;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (prec != -1 && slen > prec)
|
if (prec != -1 && slen > prec)
|
||||||
slen = prec;
|
slen = prec;
|
||||||
|
|
||||||
if (width > slen
|
if (width > slen
|
||||||
&& !(flags & FL_MINUS)) {
|
&& !(flags & FL_MINUS)) {
|
||||||
char pad =
|
char pad =
|
||||||
(flags & FL_ZERO) ?
|
(flags & FL_ZERO) ?
|
||||||
'0' : ' ';
|
'0' : ' ';
|
||||||
while (width > slen) {
|
while (width > slen) {
|
||||||
EMIT(pad);
|
EMIT(pad);
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = slen; i; i--) {
|
for (i = slen; i; i--) {
|
||||||
sch = *sarg++;
|
sch = *sarg++;
|
||||||
EMIT(sch);
|
EMIT(sch);
|
||||||
}
|
}
|
||||||
if (width > slen
|
if (width > slen
|
||||||
&& (flags & FL_MINUS)) {
|
&& (flags & FL_MINUS)) {
|
||||||
while (width > slen) {
|
while (width > slen) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
/* Output the number of
|
/* Output the number of
|
||||||
characters written */
|
characters written */
|
||||||
|
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed char *)
|
signed char *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed short *)
|
signed short *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed int *)
|
signed int *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed long *)
|
signed long *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed long long *)
|
signed long long *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifndef DISABLE_PRINT_FLOAT
|
#ifndef DISABLE_PRINT_FLOAT
|
||||||
case 'f':
|
case 'f':
|
||||||
{
|
{
|
||||||
q = flt(q, va_arg(ap, double), width, prec, ch, SIGN);
|
q = flt(q, va_arg(ap, double), width, prec, ch, SIGN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
default: /* Anything else, including % */
|
default: /* Anything else, including % */
|
||||||
EMIT(ch);
|
EMIT(ch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Null-terminate the string */
|
/* Null-terminate the string */
|
||||||
if (o < n)
|
if (o < n)
|
||||||
*q = '\0'; /* No overflow */
|
*q = '\0'; /* No overflow */
|
||||||
else if (n > 0)
|
else if (n > 0)
|
||||||
buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
|
buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SYS_BIG_DEBUG_BUFFER
|
#ifdef SYS_BIG_DEBUG_BUFFER
|
||||||
|
@ -841,7 +841,7 @@ static char string[512];
|
||||||
|
|
||||||
int vsprintf(char *buffer, const char *format, va_list ap)
|
int vsprintf(char *buffer, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
return vsnprintf(buffer, sizeof(string) - 32, format, ap);
|
return vsnprintf(buffer, sizeof(string) - 32, format, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern volatile bool sys_log_all_enable;
|
extern volatile bool sys_log_all_enable;
|
||||||
|
@ -902,25 +902,25 @@ int printf(const char *fmt, ...)
|
||||||
|
|
||||||
int sprintf(char *buffer, const char *format, ...)
|
int sprintf(char *buffer, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
|
rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int snprintf(char *buffer, size_t n, const char *format, ...)
|
int snprintf(char *buffer, size_t n, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsnprintf(buffer, n, format, ap);
|
rv = vsnprintf(buffer, n, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vMainUARTPrintString(char *pcString)
|
void vMainUARTPrintString(char *pcString)
|
||||||
|
|
12
components/bl602/bl602/evb/src/sscanf.c
Executable file → Normal file
12
components/bl602/bl602/evb/src/sscanf.c
Executable file → Normal file
|
@ -40,12 +40,12 @@
|
||||||
|
|
||||||
int sscanf(const char *str, const char *format, ...)
|
int sscanf(const char *str, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsscanf(str, format, ap);
|
rv = vsscanf(str, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
106
components/bl602/bl602/evb/src/strntoumax.c
Executable file → Normal file
106
components/bl602/bl602/evb/src/strntoumax.c
Executable file → Normal file
|
@ -44,67 +44,67 @@
|
||||||
|
|
||||||
static __inline int digitval(int ch)
|
static __inline int digitval(int ch)
|
||||||
{
|
{
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
return ch - '0';
|
return ch - '0';
|
||||||
} else if (ch >= 'A' && ch <= 'Z') {
|
} else if (ch >= 'A' && ch <= 'Z') {
|
||||||
return ch - 'A' + 10;
|
return ch - 'A' + 10;
|
||||||
} else if (ch >= 'a' && ch <= 'z') {
|
} else if (ch >= 'a' && ch <= 'z') {
|
||||||
return ch - 'a' + 10;
|
return ch - 'a' + 10;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
||||||
{
|
{
|
||||||
int minus = 0;
|
int minus = 0;
|
||||||
uintmax_t v = 0;
|
uintmax_t v = 0;
|
||||||
int d;
|
int d;
|
||||||
|
|
||||||
while (n && isspace((unsigned char)*nptr)) {
|
while (n && isspace((unsigned char)*nptr)) {
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Single optional + or - */
|
/* Single optional + or - */
|
||||||
if (n) {
|
if (n) {
|
||||||
char c = *nptr;
|
char c = *nptr;
|
||||||
if (c == '-' || c == '+') {
|
if (c == '-' || c == '+') {
|
||||||
minus = (c == '-');
|
minus = (c == '-');
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
} else if (n >= 1 && nptr[0] == '0') {
|
} else if (n >= 1 && nptr[0] == '0') {
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
base = 8;
|
base = 8;
|
||||||
} else {
|
} else {
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
} else if (base == 16) {
|
} else if (base == 16) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
||||||
v = v * base + d;
|
v = v * base + d;
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endptr)
|
if (endptr)
|
||||||
*endptr = (char *)nptr;
|
*endptr = (char *)nptr;
|
||||||
|
|
||||||
return minus ? -v : v;
|
return minus ? -v : v;
|
||||||
}
|
}
|
||||||
|
|
670
components/bl602/bl602/evb/src/vsscanf.c
Executable file → Normal file
670
components/bl602/bl602/evb/src/vsscanf.c
Executable file → Normal file
|
@ -54,391 +54,391 @@
|
||||||
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n);
|
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n);
|
||||||
|
|
||||||
enum flag {
|
enum flag {
|
||||||
FL_SPLAT = 0x01, /* Drop the value, do not assign */
|
FL_SPLAT = 0x01, /* Drop the value, do not assign */
|
||||||
FL_INV = 0x02, /* Character-set with inverse */
|
FL_INV = 0x02, /* Character-set with inverse */
|
||||||
FL_WIDTH = 0x04, /* Field width specified */
|
FL_WIDTH = 0x04, /* Field width specified */
|
||||||
FL_MINUS = 0x08, /* Negative number */
|
FL_MINUS = 0x08, /* Negative number */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ranks {
|
enum ranks {
|
||||||
rank_char = -2,
|
rank_char = -2,
|
||||||
rank_short = -1,
|
rank_short = -1,
|
||||||
rank_int = 0,
|
rank_int = 0,
|
||||||
rank_long = 1,
|
rank_long = 1,
|
||||||
rank_longlong = 2,
|
rank_longlong = 2,
|
||||||
rank_ptr = INT_MAX /* Special value used for pointers */
|
rank_ptr = INT_MAX /* Special value used for pointers */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MIN_RANK rank_char
|
#define MIN_RANK rank_char
|
||||||
#define MAX_RANK rank_longlong
|
#define MAX_RANK rank_longlong
|
||||||
|
|
||||||
#define INTMAX_RANK rank_longlong
|
#define INTMAX_RANK rank_longlong
|
||||||
#define SIZE_T_RANK rank_long
|
#define SIZE_T_RANK rank_long
|
||||||
#define PTRDIFF_T_RANK rank_long
|
#define PTRDIFF_T_RANK rank_long
|
||||||
|
|
||||||
enum bail {
|
enum bail {
|
||||||
bail_none = 0, /* No error condition */
|
bail_none = 0, /* No error condition */
|
||||||
bail_eof, /* Hit EOF */
|
bail_eof, /* Hit EOF */
|
||||||
bail_err /* Conversion mismatch */
|
bail_err /* Conversion mismatch */
|
||||||
};
|
};
|
||||||
|
|
||||||
static __inline const char *skipspace(const char *p)
|
static __inline const char *skipspace(const char *p)
|
||||||
{
|
{
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef set_bit
|
#undef set_bit
|
||||||
static __inline void set_bit(unsigned long *bitmap, unsigned int bit)
|
static __inline void set_bit(unsigned long *bitmap, unsigned int bit)
|
||||||
{
|
{
|
||||||
bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
|
bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef test_bit
|
#undef test_bit
|
||||||
static __inline int test_bit(unsigned long *bitmap, unsigned int bit)
|
static __inline int test_bit(unsigned long *bitmap, unsigned int bit)
|
||||||
{
|
{
|
||||||
return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
|
return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vsscanf(const char *buffer, const char *format, va_list ap)
|
int vsscanf(const char *buffer, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
const char *p = format;
|
const char *p = format;
|
||||||
char ch;
|
char ch;
|
||||||
unsigned char uc;
|
unsigned char uc;
|
||||||
const char *q = buffer;
|
const char *q = buffer;
|
||||||
const char *qq;
|
const char *qq;
|
||||||
uintmax_t val = 0;
|
uintmax_t val = 0;
|
||||||
int rank = rank_int; /* Default rank */
|
int rank = rank_int; /* Default rank */
|
||||||
unsigned int width = UINT_MAX;
|
unsigned int width = UINT_MAX;
|
||||||
int base;
|
int base;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
enum {
|
enum {
|
||||||
st_normal, /* Ground state */
|
st_normal, /* Ground state */
|
||||||
st_flags, /* Special flags */
|
st_flags, /* Special flags */
|
||||||
st_width, /* Field width */
|
st_width, /* Field width */
|
||||||
st_modifiers, /* Length or conversion modifiers */
|
st_modifiers, /* Length or conversion modifiers */
|
||||||
st_match_init, /* Initial state of %[ sequence */
|
st_match_init, /* Initial state of %[ sequence */
|
||||||
st_match, /* Main state of %[ sequence */
|
st_match, /* Main state of %[ sequence */
|
||||||
st_match_range, /* After - in a %[ sequence */
|
st_match_range, /* After - in a %[ sequence */
|
||||||
} state = st_normal;
|
} state = st_normal;
|
||||||
char *sarg = NULL; /* %s %c or %[ string argument */
|
char *sarg = NULL; /* %s %c or %[ string argument */
|
||||||
enum bail bail = bail_none;
|
enum bail bail = bail_none;
|
||||||
__UNUSED__ int sign;
|
__UNUSED__ int sign;
|
||||||
int converted = 0; /* Successful conversions */
|
int converted = 0; /* Successful conversions */
|
||||||
unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
|
unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
|
||||||
int matchinv = 0; /* Is match map inverted? */
|
int matchinv = 0; /* Is match map inverted? */
|
||||||
unsigned char range_start = 0;
|
unsigned char range_start = 0;
|
||||||
|
|
||||||
while ((ch = *p++) && !bail) {
|
while ((ch = *p++) && !bail) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case st_normal:
|
case st_normal:
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
state = st_flags;
|
state = st_flags;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
rank = rank_int;
|
rank = rank_int;
|
||||||
width = UINT_MAX;
|
width = UINT_MAX;
|
||||||
} else if (isspace((unsigned char)ch)) {
|
} else if (isspace((unsigned char)ch)) {
|
||||||
q = skipspace(q);
|
q = skipspace(q);
|
||||||
} else {
|
} else {
|
||||||
if (*q == ch)
|
if (*q == ch)
|
||||||
q++;
|
q++;
|
||||||
else
|
else
|
||||||
bail = bail_err; /* Match failure */
|
bail = bail_err; /* Match failure */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_flags:
|
case st_flags:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '*':
|
case '*':
|
||||||
flags |= FL_SPLAT;
|
flags |= FL_SPLAT;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
case '3':
|
case '3':
|
||||||
case '4':
|
case '4':
|
||||||
case '5':
|
case '5':
|
||||||
case '6':
|
case '6':
|
||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9':
|
||||||
width = (ch - '0');
|
width = (ch - '0');
|
||||||
state = st_width;
|
state = st_width;
|
||||||
flags |= FL_WIDTH;
|
flags |= FL_WIDTH;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_width:
|
case st_width:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
width = width * 10 + (ch - '0');
|
width = width * 10 + (ch - '0');
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_modifiers:
|
case st_modifiers:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* Length modifiers - nonterminal sequences */
|
/* Length modifiers - nonterminal sequences */
|
||||||
case 'h':
|
case 'h':
|
||||||
rank--; /* Shorter rank */
|
rank--; /* Shorter rank */
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
rank++; /* Longer rank */
|
rank++; /* Longer rank */
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
rank = INTMAX_RANK;
|
rank = INTMAX_RANK;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
rank = SIZE_T_RANK;
|
rank = SIZE_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
rank = PTRDIFF_T_RANK;
|
rank = PTRDIFF_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'q':
|
case 'q':
|
||||||
rank = rank_longlong; /* long double/long long */
|
rank = rank_longlong; /* long double/long long */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Output modifiers - terminal sequences */
|
/* Output modifiers - terminal sequences */
|
||||||
/* Next state will be normal */
|
/* Next state will be normal */
|
||||||
state = st_normal;
|
state = st_normal;
|
||||||
|
|
||||||
/* Canonicalize rank */
|
/* Canonicalize rank */
|
||||||
if (rank < MIN_RANK)
|
if (rank < MIN_RANK)
|
||||||
rank = MIN_RANK;
|
rank = MIN_RANK;
|
||||||
else if (rank > MAX_RANK)
|
else if (rank > MAX_RANK)
|
||||||
rank = MAX_RANK;
|
rank = MAX_RANK;
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'P': /* Upper case pointer */
|
case 'P': /* Upper case pointer */
|
||||||
case 'p': /* Pointer */
|
case 'p': /* Pointer */
|
||||||
rank = rank_ptr;
|
rank = rank_ptr;
|
||||||
base = 0;
|
base = 0;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'i': /* Base-independent integer */
|
case 'i': /* Base-independent integer */
|
||||||
base = 0;
|
base = 0;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'd': /* Decimal integer */
|
case 'd': /* Decimal integer */
|
||||||
base = 10;
|
base = 10;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'o': /* Octal integer */
|
case 'o': /* Octal integer */
|
||||||
base = 8;
|
base = 8;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'u': /* Unsigned decimal integer */
|
case 'u': /* Unsigned decimal integer */
|
||||||
base = 10;
|
base = 10;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'x': /* Hexadecimal integer */
|
case 'x': /* Hexadecimal integer */
|
||||||
case 'X':
|
case 'X':
|
||||||
base = 16;
|
base = 16;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'n': /* # of characters consumed */
|
case 'n': /* # of characters consumed */
|
||||||
val = (q - buffer);
|
val = (q - buffer);
|
||||||
goto set_integer;
|
goto set_integer;
|
||||||
|
|
||||||
scan_int:
|
scan_int:
|
||||||
q = skipspace(q);
|
q = skipspace(q);
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
val =
|
val =
|
||||||
strntoumax(q, (char **)&qq, base,
|
strntoumax(q, (char **)&qq, base,
|
||||||
width);
|
width);
|
||||||
if (qq == q) {
|
if (qq == q) {
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
q = qq;
|
q = qq;
|
||||||
if (!(flags & FL_SPLAT))
|
if (!(flags & FL_SPLAT))
|
||||||
converted++;
|
converted++;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
set_integer:
|
set_integer:
|
||||||
if (!(flags & FL_SPLAT)) {
|
if (!(flags & FL_SPLAT)) {
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned char *)
|
unsigned char *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned short
|
unsigned short
|
||||||
*) = val;
|
*) = val;
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned int *)
|
unsigned int *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned long *)
|
unsigned long *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned long
|
unsigned long
|
||||||
long *) = val;
|
long *) = val;
|
||||||
break;
|
break;
|
||||||
case rank_ptr:
|
case rank_ptr:
|
||||||
*va_arg(ap, void **) =
|
*va_arg(ap, void **) =
|
||||||
(void *)
|
(void *)
|
||||||
(uintptr_t)val;
|
(uintptr_t)val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* Character */
|
case 'c': /* Character */
|
||||||
/* Default width == 1 */
|
/* Default width == 1 */
|
||||||
width = (flags & FL_WIDTH) ? width : 1;
|
width = (flags & FL_WIDTH) ? width : 1;
|
||||||
if (flags & FL_SPLAT) {
|
if (flags & FL_SPLAT) {
|
||||||
while (width--) {
|
while (width--) {
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sarg = va_arg(ap, char *);
|
sarg = va_arg(ap, char *);
|
||||||
while (width--) {
|
while (width--) {
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*sarg++ = *q++;
|
*sarg++ = *q++;
|
||||||
}
|
}
|
||||||
if (!bail)
|
if (!bail)
|
||||||
converted++;
|
converted++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': /* String */
|
case 's': /* String */
|
||||||
uc = 1; /* Anything nonzero */
|
uc = 1; /* Anything nonzero */
|
||||||
if (flags & FL_SPLAT) {
|
if (flags & FL_SPLAT) {
|
||||||
while (width-- && (uc = *q) &&
|
while (width-- && (uc = *q) &&
|
||||||
!isspace(uc)) {
|
!isspace(uc)) {
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *sp;
|
char *sp;
|
||||||
sp = sarg = va_arg(ap, char *);
|
sp = sarg = va_arg(ap, char *);
|
||||||
while (width-- && (uc = *q) &&
|
while (width-- && (uc = *q) &&
|
||||||
!isspace(uc)) {
|
!isspace(uc)) {
|
||||||
*sp++ = uc;
|
*sp++ = uc;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
if (sarg != sp) {
|
if (sarg != sp) {
|
||||||
/* Terminate output */
|
/* Terminate output */
|
||||||
*sp = '\0';
|
*sp = '\0';
|
||||||
converted++;
|
converted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!uc)
|
if (!uc)
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': /* Character range */
|
case '[': /* Character range */
|
||||||
sarg = (flags & FL_SPLAT) ? NULL
|
sarg = (flags & FL_SPLAT) ? NULL
|
||||||
: va_arg(ap, char *);
|
: va_arg(ap, char *);
|
||||||
state = st_match_init;
|
state = st_match_init;
|
||||||
matchinv = 0;
|
matchinv = 0;
|
||||||
memset(matchmap, 0, sizeof matchmap);
|
memset(matchmap, 0, sizeof matchmap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%': /* %% sequence */
|
case '%': /* %% sequence */
|
||||||
if (*q == '%')
|
if (*q == '%')
|
||||||
q++;
|
q++;
|
||||||
else
|
else
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* Anything else */
|
default: /* Anything else */
|
||||||
/* Unknown sequence */
|
/* Unknown sequence */
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match_init: /* Initial state for %[ match */
|
case st_match_init: /* Initial state for %[ match */
|
||||||
if (ch == '^' && !(flags & FL_INV)) {
|
if (ch == '^' && !(flags & FL_INV)) {
|
||||||
matchinv = 1;
|
matchinv = 1;
|
||||||
} else {
|
} else {
|
||||||
set_bit(matchmap, (unsigned char)ch);
|
set_bit(matchmap, (unsigned char)ch);
|
||||||
state = st_match;
|
state = st_match;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match: /* Main state for %[ match */
|
case st_match: /* Main state for %[ match */
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
goto match_run;
|
goto match_run;
|
||||||
} else if (ch == '-') {
|
} else if (ch == '-') {
|
||||||
range_start = (unsigned char)ch;
|
range_start = (unsigned char)ch;
|
||||||
state = st_match_range;
|
state = st_match_range;
|
||||||
} else {
|
} else {
|
||||||
set_bit(matchmap, (unsigned char)ch);
|
set_bit(matchmap, (unsigned char)ch);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match_range: /* %[ match after - */
|
case st_match_range: /* %[ match after - */
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
/* - was last character */
|
/* - was last character */
|
||||||
set_bit(matchmap, (unsigned char)'-');
|
set_bit(matchmap, (unsigned char)'-');
|
||||||
goto match_run;
|
goto match_run;
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i = range_start; i < (unsigned char)ch;
|
for (i = range_start; i < (unsigned char)ch;
|
||||||
i++)
|
i++)
|
||||||
set_bit(matchmap, i);
|
set_bit(matchmap, i);
|
||||||
state = st_match;
|
state = st_match;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
match_run: /* Match expression finished */
|
match_run: /* Match expression finished */
|
||||||
qq = q;
|
qq = q;
|
||||||
uc = 1; /* Anything nonzero */
|
uc = 1; /* Anything nonzero */
|
||||||
while (width && (uc = *q)
|
while (width && (uc = *q)
|
||||||
&& test_bit(matchmap, uc)^matchinv) {
|
&& test_bit(matchmap, uc)^matchinv) {
|
||||||
if (sarg)
|
if (sarg)
|
||||||
*sarg++ = uc;
|
*sarg++ = uc;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
if (q != qq && sarg) {
|
if (q != qq && sarg) {
|
||||||
*sarg = '\0';
|
*sarg = '\0';
|
||||||
converted++;
|
converted++;
|
||||||
} else {
|
} else {
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
}
|
}
|
||||||
if (!uc)
|
if (!uc)
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bail == bail_eof && !converted)
|
if (bail == bail_eof && !converted)
|
||||||
converted = -1; /* Return EOF (-1) */
|
converted = -1; /* Return EOF (-1) */
|
||||||
|
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,21 +8,21 @@
|
||||||
#include "bflb_platform.h"
|
#include "bflb_platform.h"
|
||||||
|
|
||||||
|
|
||||||
#define bflb_crypt_printf bflb_platform_printf
|
#define bflb_crypt_printf bflb_platform_printf
|
||||||
#define bflb_crypt_printe bflb_platform_printf
|
#define bflb_crypt_printe bflb_platform_printf
|
||||||
#define bflb_crypt_printd bflb_platform_printf
|
#define bflb_crypt_printd bflb_platform_printf
|
||||||
#define bflb_crypt_printw bflb_platform_printf
|
#define bflb_crypt_printw bflb_platform_printf
|
||||||
|
|
||||||
|
|
||||||
#define BFLB_CRYPT_OK 0
|
#define BFLB_CRYPT_OK 0
|
||||||
#define BFLB_CRYPT_ERROR -1
|
#define BFLB_CRYPT_ERROR -1
|
||||||
|
|
||||||
#define BFLB_CRYPT_TYPE_AES_CBC 0
|
#define BFLB_CRYPT_TYPE_AES_CBC 0
|
||||||
#define BFLB_CRYPT_TYPE_AES_CTR 1
|
#define BFLB_CRYPT_TYPE_AES_CTR 1
|
||||||
#define BFLB_CRYPT_TYPE_CHACHA 2
|
#define BFLB_CRYPT_TYPE_CHACHA 2
|
||||||
#define BFLB_CRYPT_TYPE_AES_CCM 3
|
#define BFLB_CRYPT_TYPE_AES_CCM 3
|
||||||
#define BFLB_CRYPT_TYPE_AES_GCM 4
|
#define BFLB_CRYPT_TYPE_AES_GCM 4
|
||||||
#define BFLB_CRYPT_TYPE_CHACHAPOLY1305 5
|
#define BFLB_CRYPT_TYPE_CHACHAPOLY1305 5
|
||||||
|
|
||||||
typedef struct tag_bflb_crypt_handle_t
|
typedef struct tag_bflb_crypt_handle_t
|
||||||
{
|
{
|
||||||
|
@ -35,27 +35,27 @@ typedef struct tag_bflb_crypt_handle_t
|
||||||
int32_t bflb_crypt_init(bflb_crypt_handle_t *crypt_handle,uint8_t type);
|
int32_t bflb_crypt_init(bflb_crypt_handle_t *crypt_handle,uint8_t type);
|
||||||
|
|
||||||
int32_t bflb_crypt_setkey(bflb_crypt_handle_t *aes_handle,const uint8_t *key,
|
int32_t bflb_crypt_setkey(bflb_crypt_handle_t *aes_handle,const uint8_t *key,
|
||||||
uint8_t keytype,uint8_t key_len,const uint8_t *nonce,uint8_t nonce_len,uint8_t dir);
|
uint8_t keytype,uint8_t key_len,const uint8_t *nonce,uint8_t nonce_len,uint8_t dir);
|
||||||
|
|
||||||
int32_t bflb_crypt_setadd(bflb_crypt_handle_t *aes_handle,const uint8_t *add,
|
int32_t bflb_crypt_setadd(bflb_crypt_handle_t *aes_handle,const uint8_t *add,
|
||||||
uint8_t len,uint8_t dir);
|
uint8_t len,uint8_t dir);
|
||||||
|
|
||||||
int32_t bflb_crypt_update(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
int32_t bflb_crypt_update(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
||||||
uint32_t len,uint8_t *out);
|
uint32_t len,uint8_t *out);
|
||||||
|
|
||||||
int32_t bflb_crypt_encrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
int32_t bflb_crypt_encrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
||||||
uint32_t len,size_t offset,uint8_t *out);
|
uint32_t len,size_t offset,uint8_t *out);
|
||||||
|
|
||||||
int32_t bflb_crypt_encrypt_tag(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
int32_t bflb_crypt_encrypt_tag(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
||||||
uint32_t in_len,const uint8_t *add,uint32_t add_len,size_t offset,
|
uint32_t in_len,const uint8_t *add,uint32_t add_len,size_t offset,
|
||||||
uint8_t *out,uint8_t *tag,uint8_t tag_len);
|
uint8_t *out,uint8_t *tag,uint8_t tag_len);
|
||||||
|
|
||||||
int32_t bflb_crypt_auth_decrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
int32_t bflb_crypt_auth_decrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
||||||
uint32_t in_len,const uint8_t *add,uint32_t add_len,size_t offset,
|
uint32_t in_len,const uint8_t *add,uint32_t add_len,size_t offset,
|
||||||
uint8_t *out,const uint8_t *tag,uint8_t tag_len);
|
uint8_t *out,const uint8_t *tag,uint8_t tag_len);
|
||||||
|
|
||||||
int32_t bflb_crypt_decrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
int32_t bflb_crypt_decrypt(bflb_crypt_handle_t *aes_handle,const uint8_t *in,
|
||||||
uint32_t len,size_t offset,uint8_t *out);
|
uint32_t len,size_t offset,uint8_t *out);
|
||||||
|
|
||||||
int32_t bflb_crypt_finish(bflb_crypt_handle_t *aes_handle,uint8_t *tag,uint32_t len);
|
int32_t bflb_crypt_finish(bflb_crypt_handle_t *aes_handle,uint8_t *tag,uint32_t len);
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
#define BFLB_CRYPT_KEY_SIZE_MAX 32
|
#define BFLB_CRYPT_KEY_SIZE_MAX 32
|
||||||
#define BFLB_CRYPT_NONCE_SIZE_MAX 16
|
#define BFLB_CRYPT_NONCE_SIZE_MAX 16
|
||||||
#define BFLB_CRYPT_BLK_SIZE 16
|
#define BFLB_CRYPT_BLK_SIZE 16
|
||||||
|
|
||||||
#ifndef BFLB_CRYPT_HARDWARE
|
#ifndef BFLB_CRYPT_HARDWARE
|
||||||
typedef union tag_bflb_crypt_ctx_t
|
typedef union tag_bflb_crypt_ctx_t
|
||||||
|
@ -33,13 +33,13 @@ typedef union tag_bflb_crypt_ctx_t
|
||||||
typedef struct tag_bflb_crypt_cfg_t
|
typedef struct tag_bflb_crypt_cfg_t
|
||||||
{
|
{
|
||||||
#ifndef BFLB_CRYPT_HARDWARE
|
#ifndef BFLB_CRYPT_HARDWARE
|
||||||
uint8_t key[BFLB_CRYPT_KEY_SIZE_MAX];
|
uint8_t key[BFLB_CRYPT_KEY_SIZE_MAX];
|
||||||
//for general cipher,iv is 16 bytes, but for GCM vector test, there is a 60 bytes test
|
//for general cipher,iv is 16 bytes, but for GCM vector test, there is a 60 bytes test
|
||||||
uint8_t iv_nonce[BFLB_CRYPT_NONCE_SIZE_MAX*4];
|
uint8_t iv_nonce[BFLB_CRYPT_NONCE_SIZE_MAX*4];
|
||||||
uint8_t stream_block[BFLB_CRYPT_BLK_SIZE];
|
uint8_t stream_block[BFLB_CRYPT_BLK_SIZE];
|
||||||
uint8_t key_len;
|
uint8_t key_len;
|
||||||
uint8_t nonce_len;
|
uint8_t nonce_len;
|
||||||
uint8_t dir;
|
uint8_t dir;
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
typedef union tag_bflb_ecdsa_ctx_t
|
typedef union tag_bflb_ecdsa_ctx_t
|
||||||
{
|
{
|
||||||
#ifndef BFLB_PKA_HARDWARE
|
#ifndef BFLB_PKA_HARDWARE
|
||||||
mbedtls_ecdsa_context ctx_ecdsa;
|
mbedtls_ecdsa_context ctx_ecdsa;
|
||||||
#endif
|
#endif
|
||||||
}bflb_ecdsa_ctx_t;
|
}bflb_ecdsa_ctx_t;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ typedef struct tag_bflb_hash_handle_t
|
||||||
{
|
{
|
||||||
bflb_hash_ctx_t hash_ctx;
|
bflb_hash_ctx_t hash_ctx;
|
||||||
#ifdef BFLB_CRYPT_HARDWARE
|
#ifdef BFLB_CRYPT_HARDWARE
|
||||||
uint32_t sha_padding[64/4]; //for sha finish compute, must located at OCRAM
|
uint32_t sha_padding[64/4]; //for sha finish compute, must located at OCRAM
|
||||||
#endif
|
#endif
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
}bflb_hash_handle_t;
|
}bflb_hash_handle_t;
|
||||||
|
|
|
@ -21,7 +21,7 @@ typedef union tag_bflb_hash_ctx_t
|
||||||
mbedtls_sha256_context ctx_sha256;
|
mbedtls_sha256_context ctx_sha256;
|
||||||
mbedtls_sha512_context ctx_sha512;
|
mbedtls_sha512_context ctx_sha512;
|
||||||
#else
|
#else
|
||||||
uint32_t sha_buf[64/4]; //for sha finish compute, must located at OCRAM
|
uint32_t sha_buf[64/4]; //for sha finish compute, must located at OCRAM
|
||||||
#endif
|
#endif
|
||||||
}bflb_hash_ctx_t;
|
}bflb_hash_ctx_t;
|
||||||
|
|
||||||
|
|
|
@ -6,28 +6,28 @@ int32_t bflb_crypt_init_do(bflb_crypt_handle_t *crypt_handle,uint8_t type)
|
||||||
int32_t ret = BFLB_CRYPT_OK;
|
int32_t ret = BFLB_CRYPT_OK;
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case BFLB_CRYPT_TYPE_AES_CBC:
|
case BFLB_CRYPT_TYPE_AES_CBC:
|
||||||
case BFLB_CRYPT_TYPE_AES_CTR:
|
case BFLB_CRYPT_TYPE_AES_CTR:
|
||||||
mbedtls_aes_init((mbedtls_aes_context*)&crypt_handle->crypt_ctx);
|
mbedtls_aes_init((mbedtls_aes_context*)&crypt_handle->crypt_ctx);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
memset((ChaCha*)&crypt_handle->crypt_ctx,0,sizeof(ChaCha));
|
memset((ChaCha*)&crypt_handle->crypt_ctx,0,sizeof(ChaCha));
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_CCM:
|
case BFLB_CRYPT_TYPE_AES_CCM:
|
||||||
mbedtls_ccm_init((mbedtls_ccm_context *)&crypt_handle->crypt_ctx);
|
mbedtls_ccm_init((mbedtls_ccm_context *)&crypt_handle->crypt_ctx);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_GCM:
|
case BFLB_CRYPT_TYPE_AES_GCM:
|
||||||
mbedtls_gcm_init((mbedtls_gcm_context *)&crypt_handle->crypt_ctx);
|
mbedtls_gcm_init((mbedtls_gcm_context *)&crypt_handle->crypt_ctx);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
memset((ChaChaPoly1305*)&crypt_handle->crypt_ctx,0,sizeof(ChaChaPoly1305));
|
memset((ChaChaPoly1305*)&crypt_handle->crypt_ctx,0,sizeof(ChaChaPoly1305));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
ret=BFLB_CRYPT_ERROR;
|
ret=BFLB_CRYPT_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,14 @@ int32_t bflb_crypt_setkey_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *ke
|
||||||
{
|
{
|
||||||
int32_t ret = BFLB_CRYPT_OK;
|
int32_t ret = BFLB_CRYPT_OK;
|
||||||
|
|
||||||
memset(crypt_handle->crypt_cfg.key,0,sizeof(crypt_handle->crypt_cfg.key));
|
memset(crypt_handle->crypt_cfg.key,0,sizeof(crypt_handle->crypt_cfg.key));
|
||||||
memset(crypt_handle->crypt_cfg.iv_nonce,0,sizeof(crypt_handle->crypt_cfg.iv_nonce));
|
memset(crypt_handle->crypt_cfg.iv_nonce,0,sizeof(crypt_handle->crypt_cfg.iv_nonce));
|
||||||
memset(crypt_handle->crypt_cfg.stream_block,0,sizeof(crypt_handle->crypt_cfg.stream_block));
|
memset(crypt_handle->crypt_cfg.stream_block,0,sizeof(crypt_handle->crypt_cfg.stream_block));
|
||||||
|
|
||||||
memcpy(crypt_handle->crypt_cfg.key,key,key_len);
|
memcpy(crypt_handle->crypt_cfg.key,key,key_len);
|
||||||
memcpy(crypt_handle->crypt_cfg.iv_nonce,nonce,nonce_len);
|
memcpy(crypt_handle->crypt_cfg.iv_nonce,nonce,nonce_len);
|
||||||
crypt_handle->crypt_cfg.key_len=key_len;
|
crypt_handle->crypt_cfg.key_len=key_len;
|
||||||
crypt_handle->crypt_cfg.nonce_len=nonce_len;
|
crypt_handle->crypt_cfg.nonce_len=nonce_len;
|
||||||
|
|
||||||
switch(crypt_handle->crypt_cfg.type)
|
switch(crypt_handle->crypt_cfg.type)
|
||||||
{
|
{
|
||||||
|
@ -61,9 +61,9 @@ int32_t bflb_crypt_setkey_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *ke
|
||||||
key, key_len*8);
|
key, key_len*8);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
ret|=Chacha_SetIV((ChaCha*)&crypt_handle->crypt_ctx, nonce, nonce_len,0);
|
ret|=Chacha_SetIV((ChaCha*)&crypt_handle->crypt_ctx, nonce, nonce_len,0);
|
||||||
ret|=Chacha_SetKey((ChaCha*)&crypt_handle->crypt_ctx, key, key_len);
|
ret|=Chacha_SetKey((ChaCha*)&crypt_handle->crypt_ctx, key, key_len);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_CCM:
|
case BFLB_CRYPT_TYPE_AES_CCM:
|
||||||
ret=mbedtls_ccm_setkey((mbedtls_ccm_context*)&crypt_handle->crypt_ctx,
|
ret=mbedtls_ccm_setkey((mbedtls_ccm_context*)&crypt_handle->crypt_ctx,
|
||||||
MBEDTLS_CIPHER_ID_AES, key, key_len*8 ) ;
|
MBEDTLS_CIPHER_ID_AES, key, key_len*8 ) ;
|
||||||
|
@ -73,7 +73,7 @@ int32_t bflb_crypt_setkey_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *ke
|
||||||
MBEDTLS_CIPHER_ID_AES, key, key_len*8 ) ;
|
MBEDTLS_CIPHER_ID_AES, key, key_len*8 ) ;
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
@ -119,13 +119,13 @@ int32_t bflb_crypt_encrypt_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *i
|
||||||
MBEDTLS_AES_ENCRYPT, len, crypt_handle->crypt_cfg.iv_nonce, in, out);
|
MBEDTLS_AES_ENCRYPT, len, crypt_handle->crypt_cfg.iv_nonce, in, out);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_CTR:
|
case BFLB_CRYPT_TYPE_AES_CTR:
|
||||||
result=mbedtls_aes_crypt_ctr((mbedtls_aes_context*)&crypt_handle->crypt_ctx,
|
result=mbedtls_aes_crypt_ctr((mbedtls_aes_context*)&crypt_handle->crypt_ctx,
|
||||||
len, &offset2, crypt_handle->crypt_cfg.iv_nonce, crypt_handle->crypt_cfg.stream_block,
|
len, &offset2, crypt_handle->crypt_cfg.iv_nonce, crypt_handle->crypt_cfg.stream_block,
|
||||||
in, out );
|
in, out );
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
result=Chacha_Process((ChaCha*)&crypt_handle->crypt_ctx,out,in,len);
|
result=Chacha_Process((ChaCha*)&crypt_handle->crypt_ctx,out,in,len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
@ -153,13 +153,13 @@ int32_t bflb_crypt_encrypt_tag_do(bflb_crypt_handle_t *crypt_handle,const uint8_
|
||||||
add,add_len,in,out,tag_len,tag);
|
add,add_len,in,out,tag_len,tag);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
result = ChaCha20Poly1305_Encrypt((ChaChaPoly1305*)&crypt_handle->crypt_ctx,
|
result = ChaCha20Poly1305_Encrypt((ChaChaPoly1305*)&crypt_handle->crypt_ctx,
|
||||||
crypt_handle->crypt_cfg.key,crypt_handle->crypt_cfg.key_len,
|
crypt_handle->crypt_cfg.key,crypt_handle->crypt_cfg.key_len,
|
||||||
crypt_handle->crypt_cfg.iv_nonce,crypt_handle->crypt_cfg.nonce_len,
|
crypt_handle->crypt_cfg.iv_nonce,crypt_handle->crypt_cfg.nonce_len,
|
||||||
add,add_len,in,in_len,out,tag,tag_len);
|
add,add_len,in,in_len,out,tag,tag_len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -209,8 +209,8 @@ int32_t bflb_crypt_decrypt_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *i
|
||||||
in, out );
|
in, out );
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
result=Chacha_Process((ChaCha*)&crypt_handle->crypt_ctx,out,in,len);
|
result=Chacha_Process((ChaCha*)&crypt_handle->crypt_ctx,out,in,len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
@ -239,13 +239,13 @@ int32_t bflb_crypt_auth_decrypt_do(bflb_crypt_handle_t *crypt_handle,const uint8
|
||||||
add,add_len,tag,tag_len,in,out);
|
add,add_len,tag,tag_len,in,out);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
result = ChaCha20Poly1305_Decrypt((ChaChaPoly1305*)&crypt_handle->crypt_ctx,
|
result = ChaCha20Poly1305_Decrypt((ChaChaPoly1305*)&crypt_handle->crypt_ctx,
|
||||||
crypt_handle->crypt_cfg.key,crypt_handle->crypt_cfg.key_len,
|
crypt_handle->crypt_cfg.key,crypt_handle->crypt_cfg.key_len,
|
||||||
crypt_handle->crypt_cfg.iv_nonce,crypt_handle->crypt_cfg.nonce_len,
|
crypt_handle->crypt_cfg.iv_nonce,crypt_handle->crypt_cfg.nonce_len,
|
||||||
add,add_len,in,in_len,tag,tag_len,out);
|
add,add_len,in,in_len,tag,tag_len,out);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ int32_t bflb_crypt_finish_do(bflb_crypt_handle_t *crypt_handle,uint8_t *tag,uint
|
||||||
tag, len );
|
tag, len );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -287,9 +287,9 @@ int32_t bflb_crypt_deinit_do(bflb_crypt_handle_t *crypt_handle)
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -307,40 +307,40 @@ int32_t bflb_crypt_init_do(bflb_crypt_handle_t *crypt_handle,uint8_t type)
|
||||||
int32_t bflb_crypt_setkey_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *key, uint8_t keytype, uint8_t key_len,
|
int32_t bflb_crypt_setkey_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *key, uint8_t keytype, uint8_t key_len,
|
||||||
const uint8_t *nonce,uint8_t nonce_len,uint8_t dir)
|
const uint8_t *nonce,uint8_t nonce_len,uint8_t dir)
|
||||||
{
|
{
|
||||||
int32_t ret = BFLB_CRYPT_OK;
|
int32_t ret = BFLB_CRYPT_OK;
|
||||||
|
|
||||||
switch(crypt_handle->crypt_cfg.type)
|
switch(crypt_handle->crypt_cfg.type)
|
||||||
{
|
{
|
||||||
case BFLB_CRYPT_TYPE_AES_CBC:
|
case BFLB_CRYPT_TYPE_AES_CBC:
|
||||||
Sec_Eng_AES_Enable_BE(SEC_ENG_AES_ID0);
|
Sec_Eng_AES_Enable_BE(SEC_ENG_AES_ID0);
|
||||||
Sec_Eng_AES_Init(&aesCtx,SEC_ENG_AES_ID0,SEC_ENG_AES_CBC,(SEC_ENG_AES_Key_Type)keytype,
|
Sec_Eng_AES_Init(&aesCtx,SEC_ENG_AES_ID0,SEC_ENG_AES_CBC,(SEC_ENG_AES_Key_Type)keytype,
|
||||||
BFLB_CRYPT_DIR_ENCRYPT==dir?SEC_ENG_AES_ENCRYPTION:SEC_ENG_AES_DECRYPTION);
|
BFLB_CRYPT_DIR_ENCRYPT==dir?SEC_ENG_AES_ENCRYPTION:SEC_ENG_AES_DECRYPTION);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_CTR:
|
case BFLB_CRYPT_TYPE_AES_CTR:
|
||||||
Sec_Eng_AES_Enable_BE(SEC_ENG_AES_ID0);
|
Sec_Eng_AES_Enable_BE(SEC_ENG_AES_ID0);
|
||||||
Sec_Eng_AES_Init(&aesCtx,SEC_ENG_AES_ID0,SEC_ENG_AES_CTR,(SEC_ENG_AES_Key_Type)keytype,
|
Sec_Eng_AES_Init(&aesCtx,SEC_ENG_AES_ID0,SEC_ENG_AES_CTR,(SEC_ENG_AES_Key_Type)keytype,
|
||||||
BFLB_CRYPT_DIR_ENCRYPT==dir?SEC_ENG_AES_ENCRYPTION:SEC_ENG_AES_DECRYPTION);
|
BFLB_CRYPT_DIR_ENCRYPT==dir?SEC_ENG_AES_ENCRYPTION:SEC_ENG_AES_DECRYPTION);
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_CCM:
|
case BFLB_CRYPT_TYPE_AES_CCM:
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_AES_GCM:
|
case BFLB_CRYPT_TYPE_AES_GCM:
|
||||||
break;
|
break;
|
||||||
case BFLB_CRYPT_TYPE_CHACHA:
|
case BFLB_CRYPT_TYPE_CHACHA:
|
||||||
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
case BFLB_CRYPT_TYPE_CHACHAPOLY1305:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if key len is 0, means key is from efuse and *key value is key_sel value */
|
/* if key len is 0, means key is from efuse and *key value is key_sel value */
|
||||||
if(key_len==0){
|
if(key_len==0){
|
||||||
Sec_Eng_AES_Set_Key_IV_BE(SEC_ENG_AES_ID0,SEC_ENG_AES_KEY_HW,key,nonce);
|
Sec_Eng_AES_Set_Key_IV_BE(SEC_ENG_AES_ID0,SEC_ENG_AES_KEY_HW,key,nonce);
|
||||||
}else{
|
}else{
|
||||||
Sec_Eng_AES_Set_Key_IV_BE(SEC_ENG_AES_ID0,SEC_ENG_AES_KEY_SW,key,nonce);
|
Sec_Eng_AES_Set_Key_IV_BE(SEC_ENG_AES_ID0,SEC_ENG_AES_KEY_SW,key,nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t bflb_crypt_setadd_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *add,uint8_t len,
|
int32_t bflb_crypt_setadd_do(bflb_crypt_handle_t *crypt_handle,const uint8_t *add,uint8_t len,
|
||||||
|
@ -421,7 +421,7 @@ int32_t bflb_crypt_deinit_do(bflb_crypt_handle_t *crypt_handle)
|
||||||
case BFLB_CRYPT_TYPE_AES_CTR:
|
case BFLB_CRYPT_TYPE_AES_CTR:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_crypt_printe("unsupported type\r\n");
|
bflb_crypt_printe("unsupported type\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -448,8 +448,8 @@ int32_t bflb_crypt_setkey(bflb_crypt_handle_t *crypt_handle,const uint8_t *key,u
|
||||||
result=bflb_crypt_setkey_do(crypt_handle,key,keytype,key_len,nonce,nonce_len,dir);
|
result=bflb_crypt_setkey_do(crypt_handle,key,keytype,key_len,nonce,nonce_len,dir);
|
||||||
|
|
||||||
if(result!=BFLB_CRYPT_OK){
|
if(result!=BFLB_CRYPT_OK){
|
||||||
bflb_crypt_printe("crypt set key fail\r\n");
|
bflb_crypt_printe("crypt set key fail\r\n");
|
||||||
result=BFLB_CRYPT_ERROR;
|
result=BFLB_CRYPT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -463,8 +463,8 @@ int32_t bflb_crypt_setadd(bflb_crypt_handle_t *crypt_handle,const uint8_t *add,u
|
||||||
result = bflb_crypt_setadd_do(crypt_handle,add,len,dir);
|
result = bflb_crypt_setadd_do(crypt_handle,add,len,dir);
|
||||||
|
|
||||||
if(result!=BFLB_CRYPT_OK){
|
if(result!=BFLB_CRYPT_OK){
|
||||||
bflb_crypt_printe("crypt set add fail\r\n");
|
bflb_crypt_printe("crypt set add fail\r\n");
|
||||||
result=BFLB_CRYPT_ERROR;
|
result=BFLB_CRYPT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -473,7 +473,7 @@ int32_t bflb_crypt_setadd(bflb_crypt_handle_t *crypt_handle,const uint8_t *add,u
|
||||||
int32_t bflb_crypt_encrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
int32_t bflb_crypt_encrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
||||||
size_t offset,uint8_t *out)
|
size_t offset,uint8_t *out)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result=bflb_crypt_encrypt_do(crypt_handle,in,len, offset,out);
|
result=bflb_crypt_encrypt_do(crypt_handle,in,len, offset,out);
|
||||||
|
|
||||||
|
@ -490,13 +490,13 @@ int32_t bflb_crypt_encrypt_tag(bflb_crypt_handle_t *crypt_handle,const uint8_t *
|
||||||
const uint8_t *add,uint32_t add_len,size_t offset,uint8_t *out,
|
const uint8_t *add,uint32_t add_len,size_t offset,uint8_t *out,
|
||||||
uint8_t *tag,uint8_t tag_len)
|
uint8_t *tag,uint8_t tag_len)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result= bflb_crypt_encrypt_tag_do(crypt_handle,in,in_len,add,add_len,offset,out,tag,tag_len);
|
result= bflb_crypt_encrypt_tag_do(crypt_handle,in,in_len,add,add_len,offset,out,tag,tag_len);
|
||||||
|
|
||||||
if( result != BFLB_CRYPT_OK)
|
if( result != BFLB_CRYPT_OK)
|
||||||
{
|
{
|
||||||
bflb_crypt_printe("crypt encrypt and tag fail\r\n");
|
bflb_crypt_printe("crypt encrypt and tag fail\r\n");
|
||||||
return BFLB_CRYPT_ERROR;
|
return BFLB_CRYPT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ int32_t bflb_crypt_encrypt_tag(bflb_crypt_handle_t *crypt_handle,const uint8_t *
|
||||||
int32_t bflb_crypt_update(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
int32_t bflb_crypt_update(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
||||||
uint8_t *out)
|
uint8_t *out)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result=bflb_crypt_update_do(crypt_handle,in,len,out);
|
result=bflb_crypt_update_do(crypt_handle,in,len,out);
|
||||||
|
|
||||||
|
@ -523,7 +523,7 @@ int32_t bflb_crypt_update(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,ui
|
||||||
int32_t bflb_crypt_decrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
int32_t bflb_crypt_decrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t *in,uint32_t len,
|
||||||
size_t offset,uint8_t *out)
|
size_t offset,uint8_t *out)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result=bflb_crypt_decrypt_do(crypt_handle,in,len,offset,out);
|
result=bflb_crypt_decrypt_do(crypt_handle,in,len,offset,out);
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ int32_t bflb_crypt_auth_decrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t
|
||||||
const uint8_t *add,uint32_t add_len,size_t offset,uint8_t *out,
|
const uint8_t *add,uint32_t add_len,size_t offset,uint8_t *out,
|
||||||
const uint8_t *tag,uint8_t tag_len)
|
const uint8_t *tag,uint8_t tag_len)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result= bflb_crypt_auth_decrypt_do(crypt_handle,in,in_len,add,add_len,offset,out,tag,tag_len);
|
result= bflb_crypt_auth_decrypt_do(crypt_handle,in,in_len,add,add_len,offset,out,tag,tag_len);
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ int32_t bflb_crypt_auth_decrypt(bflb_crypt_handle_t *crypt_handle,const uint8_t
|
||||||
|
|
||||||
int32_t bflb_crypt_finish(bflb_crypt_handle_t *crypt_handle,uint8_t *tag,uint32_t len)
|
int32_t bflb_crypt_finish(bflb_crypt_handle_t *crypt_handle,uint8_t *tag,uint32_t len)
|
||||||
{
|
{
|
||||||
int32_t result;
|
int32_t result;
|
||||||
|
|
||||||
result=bflb_crypt_finish_do(crypt_handle,tag,len);
|
result=bflb_crypt_finish_do(crypt_handle,tag,len);
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ int32_t bflb_crypt_finish(bflb_crypt_handle_t *crypt_handle,uint8_t *tag,uint32_
|
||||||
int32_t bflb_crypt_deinit(bflb_crypt_handle_t *crypt_handle)
|
int32_t bflb_crypt_deinit(bflb_crypt_handle_t *crypt_handle)
|
||||||
{
|
{
|
||||||
|
|
||||||
bflb_crypt_deinit_do(crypt_handle);
|
bflb_crypt_deinit_do(crypt_handle);
|
||||||
memset(crypt_handle,0,sizeof(bflb_crypt_handle_t));
|
memset(crypt_handle,0,sizeof(bflb_crypt_handle_t));
|
||||||
|
|
||||||
return BFLB_CRYPT_OK;
|
return BFLB_CRYPT_OK;
|
||||||
|
|
|
@ -1021,10 +1021,10 @@ int32_t bflb_ecdh_get_public_key( uint8_t id,const uint32_t *pkX,const uint32_t
|
||||||
|
|
||||||
int32_t bflb_ecdsa_get_private_key( uint8_t id,uint32_t *private_key)
|
int32_t bflb_ecdsa_get_private_key( uint8_t id,uint32_t *private_key)
|
||||||
{
|
{
|
||||||
if(bflb_ecc_get_random_value(private_key,(uint32_t *)secp256r1N,32)<0){
|
if(bflb_ecc_get_random_value(private_key,(uint32_t *)secp256r1N,32)<0){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t bflb_ecdsa_sign( uint8_t id,const uint32_t *private_key,const uint32_t *random_k,const uint32_t *hash,uint32_t *r,uint32_t *s)
|
int32_t bflb_ecdsa_sign( uint8_t id,const uint32_t *private_key,const uint32_t *random_k,const uint32_t *hash,uint32_t *r,uint32_t *s)
|
||||||
|
|
|
@ -32,8 +32,8 @@ int32_t bflb_hash_init(bflb_hash_handle_t *hash_handle,uint8_t type)
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case BFLB_HASH_TYPE_SHA1 :
|
case BFLB_HASH_TYPE_SHA1 :
|
||||||
ret=BFLB_HASH_ERROR;
|
ret=BFLB_HASH_ERROR;
|
||||||
bflb_hash_printe("unsupported type\r\n");
|
bflb_hash_printe("unsupported type\r\n");
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA224:
|
case BFLB_HASH_TYPE_SHA224:
|
||||||
Sec_Eng_SHA256_Init(&shaCtx,SEC_ENG_SHA_ID0,SEC_ENG_SHA224,(uint32_t *)hash_handle->hash_ctx.sha_buf,
|
Sec_Eng_SHA256_Init(&shaCtx,SEC_ENG_SHA_ID0,SEC_ENG_SHA224,(uint32_t *)hash_handle->hash_ctx.sha_buf,
|
||||||
|
@ -45,8 +45,8 @@ int32_t bflb_hash_init(bflb_hash_handle_t *hash_handle,uint8_t type)
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA384:
|
case BFLB_HASH_TYPE_SHA384:
|
||||||
case BFLB_HASH_TYPE_SHA512:
|
case BFLB_HASH_TYPE_SHA512:
|
||||||
ret=BFLB_HASH_ERROR;
|
ret=BFLB_HASH_ERROR;
|
||||||
bflb_hash_printe("unsupported type\r\n");
|
bflb_hash_printe("unsupported type\r\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bflb_hash_printe("unsupported type\r\n");
|
bflb_hash_printe("unsupported type\r\n");
|
||||||
|
@ -71,10 +71,10 @@ int32_t bflb_hash_start(bflb_hash_handle_t *hash_handle)
|
||||||
case BFLB_HASH_TYPE_SHA1:
|
case BFLB_HASH_TYPE_SHA1:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA224:
|
case BFLB_HASH_TYPE_SHA224:
|
||||||
Sec_Eng_SHA_Start(SEC_ENG_SHA_ID0);
|
Sec_Eng_SHA_Start(SEC_ENG_SHA_ID0);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA256:
|
case BFLB_HASH_TYPE_SHA256:
|
||||||
Sec_Eng_SHA_Start(SEC_ENG_SHA_ID0);
|
Sec_Eng_SHA_Start(SEC_ENG_SHA_ID0);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA384:
|
case BFLB_HASH_TYPE_SHA384:
|
||||||
break;
|
break;
|
||||||
|
@ -86,7 +86,7 @@ int32_t bflb_hash_start(bflb_hash_handle_t *hash_handle)
|
||||||
|
|
||||||
}
|
}
|
||||||
if(ret!=0){
|
if(ret!=0){
|
||||||
bflb_hash_printe("hash start fail\r\n");
|
bflb_hash_printe("hash start fail\r\n");
|
||||||
ret=BFLB_HASH_ERROR;
|
ret=BFLB_HASH_ERROR;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -100,11 +100,11 @@ int32_t bflb_hash_update(bflb_hash_handle_t *hash_handle,const uint8_t *in,uint3
|
||||||
{
|
{
|
||||||
case BFLB_HASH_TYPE_SHA1:
|
case BFLB_HASH_TYPE_SHA1:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA224:
|
case BFLB_HASH_TYPE_SHA224:
|
||||||
Sec_Eng_SHA256_Update(&shaCtx,SEC_ENG_SHA_ID0,in, len);
|
Sec_Eng_SHA256_Update(&shaCtx,SEC_ENG_SHA_ID0,in, len);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA256:
|
case BFLB_HASH_TYPE_SHA256:
|
||||||
Sec_Eng_SHA256_Update(&shaCtx,SEC_ENG_SHA_ID0,in, len);
|
Sec_Eng_SHA256_Update(&shaCtx,SEC_ENG_SHA_ID0,in, len);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA384:
|
case BFLB_HASH_TYPE_SHA384:
|
||||||
break;
|
break;
|
||||||
|
@ -116,7 +116,7 @@ int32_t bflb_hash_update(bflb_hash_handle_t *hash_handle,const uint8_t *in,uint3
|
||||||
|
|
||||||
}
|
}
|
||||||
if(ret!=0){
|
if(ret!=0){
|
||||||
bflb_hash_printe("hash update fail\r\n");
|
bflb_hash_printe("hash update fail\r\n");
|
||||||
ret=BFLB_HASH_ERROR;
|
ret=BFLB_HASH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,10 +132,10 @@ int32_t bflb_hash_finish(bflb_hash_handle_t *hash_handle,uint8_t *out)
|
||||||
case BFLB_HASH_TYPE_SHA1:
|
case BFLB_HASH_TYPE_SHA1:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA224:
|
case BFLB_HASH_TYPE_SHA224:
|
||||||
Sec_Eng_SHA256_Finish(&shaCtx,SEC_ENG_SHA_ID0,out);
|
Sec_Eng_SHA256_Finish(&shaCtx,SEC_ENG_SHA_ID0,out);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA256:
|
case BFLB_HASH_TYPE_SHA256:
|
||||||
Sec_Eng_SHA256_Finish(&shaCtx,SEC_ENG_SHA_ID0,out);
|
Sec_Eng_SHA256_Finish(&shaCtx,SEC_ENG_SHA_ID0,out);
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA384:
|
case BFLB_HASH_TYPE_SHA384:
|
||||||
break;
|
break;
|
||||||
|
@ -147,7 +147,7 @@ int32_t bflb_hash_finish(bflb_hash_handle_t *hash_handle,uint8_t *out)
|
||||||
|
|
||||||
}
|
}
|
||||||
if(ret!=0){
|
if(ret!=0){
|
||||||
bflb_hash_printe("hash finish fail\r\n");
|
bflb_hash_printe("hash finish fail\r\n");
|
||||||
ret=BFLB_HASH_ERROR;
|
ret=BFLB_HASH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ int32_t bflb_hash_deinit(bflb_hash_handle_t *hash_handle)
|
||||||
case BFLB_HASH_TYPE_SHA1:
|
case BFLB_HASH_TYPE_SHA1:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA224:
|
case BFLB_HASH_TYPE_SHA224:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA256:
|
case BFLB_HASH_TYPE_SHA256:
|
||||||
break;
|
break;
|
||||||
case BFLB_HASH_TYPE_SHA384:
|
case BFLB_HASH_TYPE_SHA384:
|
||||||
|
|
|
@ -15,8 +15,8 @@ int32_t bflb_rsa_set_parameter(bflb_rsa_handle_t *rsa_handle,int type,uint8_t *v
|
||||||
int32_t ret = BFLB_RSA_OK;
|
int32_t ret = BFLB_RSA_OK;
|
||||||
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case BFLB_RSA_PARA_N:
|
case BFLB_RSA_PARA_N:
|
||||||
mbedtls_mpi_read_binary(&rsa->N,value,len);
|
mbedtls_mpi_read_binary(&rsa->N,value,len);
|
||||||
rsa->len = ( mbedtls_mpi_bitlen( &rsa->N ) + 7 ) >> 3;
|
rsa->len = ( mbedtls_mpi_bitlen( &rsa->N ) + 7 ) >> 3;
|
||||||
|
@ -45,7 +45,7 @@ int32_t bflb_rsa_set_parameter(bflb_rsa_handle_t *rsa_handle,int type,uint8_t *v
|
||||||
default:
|
default:
|
||||||
ret=BFLB_RSA_ERROR;
|
ret=BFLB_RSA_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ int32_t bflb_rsa_check_private(bflb_rsa_handle_t *rsa_handle)
|
||||||
int32_t ret = BFLB_RSA_OK;
|
int32_t ret = BFLB_RSA_OK;
|
||||||
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
||||||
|
|
||||||
if( ( ret = mbedtls_rsa_check_privkey( rsa ) ) != 0 )
|
if( ( ret = mbedtls_rsa_check_privkey( rsa ) ) != 0 )
|
||||||
{
|
{
|
||||||
bflb_rsa_printe("failed\r\n!rsa_check_privkey failed with -0x%0x\n", -ret );
|
bflb_rsa_printe("failed\r\n!rsa_check_privkey failed with -0x%0x\n", -ret );
|
||||||
return BFLB_RSA_ERROR;
|
return BFLB_RSA_ERROR;
|
||||||
|
@ -69,7 +69,7 @@ int32_t bflb_rsa_check_public(bflb_rsa_handle_t *rsa_handle)
|
||||||
int32_t ret = BFLB_RSA_OK;
|
int32_t ret = BFLB_RSA_OK;
|
||||||
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
||||||
|
|
||||||
if( ( ret = mbedtls_rsa_check_pubkey( rsa ) ) != 0 )
|
if( ( ret = mbedtls_rsa_check_pubkey( rsa ) ) != 0 )
|
||||||
{
|
{
|
||||||
bflb_rsa_printe("failed\r\n!rsa_check_privkey failed with -0x%0x\n", -ret );
|
bflb_rsa_printe("failed\r\n!rsa_check_privkey failed with -0x%0x\n", -ret );
|
||||||
return BFLB_RSA_ERROR;
|
return BFLB_RSA_ERROR;
|
||||||
|
@ -84,8 +84,8 @@ int32_t bflb_rsa_sign( bflb_rsa_handle_t *rsa_handle,const uint8_t *hash,
|
||||||
int32_t ret = BFLB_RSA_OK;
|
int32_t ret = BFLB_RSA_OK;
|
||||||
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
||||||
|
|
||||||
ret = mbedtls_rsa_pkcs1_sign( rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE,
|
ret = mbedtls_rsa_pkcs1_sign( rsa, NULL, NULL, MBEDTLS_RSA_PRIVATE,
|
||||||
(mbedtls_md_type_t)bflb_hash_get_type(hashtype),
|
(mbedtls_md_type_t)bflb_hash_get_type(hashtype),
|
||||||
hashlen, hash, sig );
|
hashlen, hash, sig );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ int32_t bflb_rsa_verify( bflb_rsa_handle_t *rsa_handle,const uint8_t *hash,
|
||||||
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
mbedtls_rsa_context* rsa=(mbedtls_rsa_context*)&rsa_handle->rsa_ctx;
|
||||||
|
|
||||||
ret = mbedtls_rsa_pkcs1_verify( rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC,
|
ret = mbedtls_rsa_pkcs1_verify( rsa, NULL, NULL, MBEDTLS_RSA_PUBLIC,
|
||||||
(mbedtls_md_type_t)bflb_hash_get_type(hashtype),
|
(mbedtls_md_type_t)bflb_hash_get_type(hashtype),
|
||||||
hashlen, hash, sig );
|
hashlen, hash, sig );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,22 +7,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
struct ctype_base
|
struct ctype_base
|
||||||
{
|
{
|
||||||
// Non-standard typedefs.
|
// Non-standard typedefs.
|
||||||
typedef const int* __to_type;
|
typedef const int* __to_type;
|
||||||
|
|
||||||
// NB: Offsets into ctype<char>::_M_table force a particular size
|
// NB: Offsets into ctype<char>::_M_table force a particular size
|
||||||
// on the mask type. Because of this, we don't use an enum.
|
// on the mask type. Because of this, we don't use an enum.
|
||||||
typedef char mask;
|
typedef char mask;
|
||||||
static const mask upper = _U;
|
static const mask upper = _U;
|
||||||
static const mask lower = _L;
|
static const mask lower = _L;
|
||||||
static const mask alpha = _U | _L;
|
static const mask alpha = _U | _L;
|
||||||
static const mask digit = _N;
|
static const mask digit = _N;
|
||||||
static const mask xdigit = _X | _N;
|
static const mask xdigit = _X | _N;
|
||||||
static const mask space = _S;
|
static const mask space = _S;
|
||||||
static const mask print = _P | _U | _L | _N | _B;
|
static const mask print = _P | _U | _L | _N | _B;
|
||||||
static const mask graph = _P | _U | _L | _N;
|
static const mask graph = _P | _U | _L | _N;
|
||||||
static const mask cntrl = _C;
|
static const mask cntrl = _C;
|
||||||
static const mask punct = _P;
|
static const mask punct = _P;
|
||||||
static const mask alnum = _U | _L | _N;
|
static const mask alnum = _U | _L | _N;
|
||||||
};
|
};
|
||||||
|
|
||||||
_GLIBCXX_END_NAMESPACE_VERSION
|
_GLIBCXX_END_NAMESPACE_VERSION
|
||||||
|
|
|
@ -28,14 +28,14 @@
|
||||||
* blank = '\t' || ' ' (per POSIX requirement)
|
* blank = '\t' || ' ' (per POSIX requirement)
|
||||||
*/
|
*/
|
||||||
enum {
|
enum {
|
||||||
__ctype_upper = _U,
|
__ctype_upper = _U,
|
||||||
__ctype_lower = _L,
|
__ctype_lower = _L,
|
||||||
__ctype_digit = _N,
|
__ctype_digit = _N,
|
||||||
__ctype_xdigit = _S,
|
__ctype_xdigit = _S,
|
||||||
__ctype_space = _P,
|
__ctype_space = _P,
|
||||||
__ctype_print = _C,
|
__ctype_print = _C,
|
||||||
__ctype_punct = _X,
|
__ctype_punct = _X,
|
||||||
__ctype_cntrl = _B
|
__ctype_cntrl = _B
|
||||||
};
|
};
|
||||||
|
|
||||||
__extern int isalnum(int);
|
__extern int isalnum(int);
|
||||||
|
@ -58,69 +58,69 @@ extern const unsigned char __ctypes[];
|
||||||
|
|
||||||
__must_inline int __ctype_isalnum(int __c)
|
__must_inline int __ctype_isalnum(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] &
|
return __ctypes[__c + 1] &
|
||||||
(__ctype_upper | __ctype_lower | __ctype_digit);
|
(__ctype_upper | __ctype_lower | __ctype_digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isalpha(int __c)
|
__must_inline int __ctype_isalpha(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
|
return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isascii(int __c)
|
__must_inline int __ctype_isascii(int __c)
|
||||||
{
|
{
|
||||||
return !(__c & ~0x7f);
|
return !(__c & ~0x7f);
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isblank(int __c)
|
__must_inline int __ctype_isblank(int __c)
|
||||||
{
|
{
|
||||||
return (__c == '\t') || (__c == ' ');
|
return (__c == '\t') || (__c == ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_iscntrl(int __c)
|
__must_inline int __ctype_iscntrl(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_cntrl;
|
return __ctypes[__c + 1] & __ctype_cntrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isdigit(int __c)
|
__must_inline int __ctype_isdigit(int __c)
|
||||||
{
|
{
|
||||||
return ((unsigned)__c - '0') <= 9;
|
return ((unsigned)__c - '0') <= 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isgraph(int __c)
|
__must_inline int __ctype_isgraph(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] &
|
return __ctypes[__c + 1] &
|
||||||
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
|
(__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_islower(int __c)
|
__must_inline int __ctype_islower(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_lower;
|
return __ctypes[__c + 1] & __ctype_lower;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isprint(int __c)
|
__must_inline int __ctype_isprint(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_print;
|
return __ctypes[__c + 1] & __ctype_print;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_ispunct(int __c)
|
__must_inline int __ctype_ispunct(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_punct;
|
return __ctypes[__c + 1] & __ctype_punct;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isspace(int __c)
|
__must_inline int __ctype_isspace(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_space;
|
return __ctypes[__c + 1] & __ctype_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isupper(int __c)
|
__must_inline int __ctype_isupper(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_upper;
|
return __ctypes[__c + 1] & __ctype_upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_isxdigit(int __c)
|
__must_inline int __ctype_isxdigit(int __c)
|
||||||
{
|
{
|
||||||
return __ctypes[__c + 1] & __ctype_xdigit;
|
return __ctypes[__c + 1] & __ctype_xdigit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
|
/* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
|
||||||
|
@ -129,12 +129,12 @@ __must_inline int __ctype_isxdigit(int __c)
|
||||||
|
|
||||||
__must_inline int __ctype_toupper(int __c)
|
__must_inline int __ctype_toupper(int __c)
|
||||||
{
|
{
|
||||||
return __ctype_islower(__c) ? _toupper(__c) : __c;
|
return __ctype_islower(__c) ? _toupper(__c) : __c;
|
||||||
}
|
}
|
||||||
|
|
||||||
__must_inline int __ctype_tolower(int __c)
|
__must_inline int __ctype_tolower(int __c)
|
||||||
{
|
{
|
||||||
return __ctype_isupper(__c) ? _tolower(__c) : __c;
|
return __ctype_isupper(__c) ? _tolower(__c) : __c;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _CTYPE_H */
|
#endif /* _CTYPE_H */
|
||||||
|
|
|
@ -13,4 +13,4 @@
|
||||||
|
|
||||||
#define __alias(x) __attribute__((weak, alias(x)))
|
#define __alias(x) __attribute__((weak, alias(x)))
|
||||||
|
|
||||||
#endif /* _EXTERN_H */
|
#endif /* _EXTERN_H */
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
#include <extern.h>
|
#include <extern.h>
|
||||||
|
|
||||||
#define FNM_NOMATCH 1
|
#define FNM_NOMATCH 1
|
||||||
|
|
||||||
#define FNM_PATHNAME 1
|
#define FNM_PATHNAME 1
|
||||||
#define FNM_FILE_NAME FNM_PATHNAME
|
#define FNM_FILE_NAME FNM_PATHNAME
|
||||||
#define FNM_NOESCAPE 2
|
#define FNM_NOESCAPE 2
|
||||||
#define FNM_PERIOD 4
|
#define FNM_PERIOD 4
|
||||||
|
|
||||||
__extern int fnmatch(const char *, const char *, int);
|
__extern int fnmatch(const char *, const char *, int);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
static __inline intmax_t imaxabs(intmax_t __n)
|
static __inline intmax_t imaxabs(intmax_t __n)
|
||||||
{
|
{
|
||||||
return (__n < (intmax_t) 0) ? -__n : __n;
|
return (__n < (intmax_t) 0) ? -__n : __n;
|
||||||
}
|
}
|
||||||
|
|
||||||
__extern intmax_t strtoimax(const char *, char **, int);
|
__extern intmax_t strtoimax(const char *, char **, int);
|
||||||
|
@ -24,204 +24,204 @@ __extern uintmax_t strntoumax(const char *, char **, int, size_t);
|
||||||
|
|
||||||
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
|
#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
|
||||||
|
|
||||||
#define PRId8 "d"
|
#define PRId8 "d"
|
||||||
#define PRId16 "d"
|
#define PRId16 "d"
|
||||||
#define PRId32 "d"
|
#define PRId32 "d"
|
||||||
#define PRId64 __PRI64_RANK "d"
|
#define PRId64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define PRIdLEAST8 "d"
|
#define PRIdLEAST8 "d"
|
||||||
#define PRIdLEAST16 "d"
|
#define PRIdLEAST16 "d"
|
||||||
#define PRIdLEAST32 "d"
|
#define PRIdLEAST32 "d"
|
||||||
#define PRIdLEAST64 __PRI64_RANK "d"
|
#define PRIdLEAST64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define PRIdFAST8 "d"
|
#define PRIdFAST8 "d"
|
||||||
#define PRIdFAST16 __PRIFAST_RANK "d"
|
#define PRIdFAST16 __PRIFAST_RANK "d"
|
||||||
#define PRIdFAST32 __PRIFAST_RANK "d"
|
#define PRIdFAST32 __PRIFAST_RANK "d"
|
||||||
#define PRIdFAST64 __PRI64_RANK "d"
|
#define PRIdFAST64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define PRIdMAX __PRI64_RANK "d"
|
#define PRIdMAX __PRI64_RANK "d"
|
||||||
#define PRIdPTR __PRIPTR_RANK "d"
|
#define PRIdPTR __PRIPTR_RANK "d"
|
||||||
|
|
||||||
#define PRIi8 "i"
|
#define PRIi8 "i"
|
||||||
#define PRIi16 "i"
|
#define PRIi16 "i"
|
||||||
#define PRIi32 "i"
|
#define PRIi32 "i"
|
||||||
#define PRIi64 __PRI64_RANK "i"
|
#define PRIi64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define PRIiLEAST8 "i"
|
#define PRIiLEAST8 "i"
|
||||||
#define PRIiLEAST16 "i"
|
#define PRIiLEAST16 "i"
|
||||||
#define PRIiLEAST32 "i"
|
#define PRIiLEAST32 "i"
|
||||||
#define PRIiLEAST64 __PRI64_RANK "i"
|
#define PRIiLEAST64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define PRIiFAST8 "i"
|
#define PRIiFAST8 "i"
|
||||||
#define PRIiFAST16 __PRIFAST_RANK "i"
|
#define PRIiFAST16 __PRIFAST_RANK "i"
|
||||||
#define PRIiFAST32 __PRIFAST_RANK "i"
|
#define PRIiFAST32 __PRIFAST_RANK "i"
|
||||||
#define PRIiFAST64 __PRI64_RANK "i"
|
#define PRIiFAST64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define PRIiMAX __PRI64_RANK "i"
|
#define PRIiMAX __PRI64_RANK "i"
|
||||||
#define PRIiPTR __PRIPTR_RANK "i"
|
#define PRIiPTR __PRIPTR_RANK "i"
|
||||||
|
|
||||||
#define PRIo8 "o"
|
#define PRIo8 "o"
|
||||||
#define PRIo16 "o"
|
#define PRIo16 "o"
|
||||||
#define PRIo32 "o"
|
#define PRIo32 "o"
|
||||||
#define PRIo64 __PRI64_RANK "o"
|
#define PRIo64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define PRIoLEAST8 "o"
|
#define PRIoLEAST8 "o"
|
||||||
#define PRIoLEAST16 "o"
|
#define PRIoLEAST16 "o"
|
||||||
#define PRIoLEAST32 "o"
|
#define PRIoLEAST32 "o"
|
||||||
#define PRIoLEAST64 __PRI64_RANK "o"
|
#define PRIoLEAST64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define PRIoFAST8 "o"
|
#define PRIoFAST8 "o"
|
||||||
#define PRIoFAST16 __PRIFAST_RANK "o"
|
#define PRIoFAST16 __PRIFAST_RANK "o"
|
||||||
#define PRIoFAST32 __PRIFAST_RANK "o"
|
#define PRIoFAST32 __PRIFAST_RANK "o"
|
||||||
#define PRIoFAST64 __PRI64_RANK "o"
|
#define PRIoFAST64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define PRIoMAX __PRI64_RANK "o"
|
#define PRIoMAX __PRI64_RANK "o"
|
||||||
#define PRIoPTR __PRIPTR_RANK "o"
|
#define PRIoPTR __PRIPTR_RANK "o"
|
||||||
|
|
||||||
#define PRIu8 "u"
|
#define PRIu8 "u"
|
||||||
#define PRIu16 "u"
|
#define PRIu16 "u"
|
||||||
#define PRIu32 "u"
|
#define PRIu32 "u"
|
||||||
#define PRIu64 __PRI64_RANK "u"
|
#define PRIu64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define PRIuLEAST8 "u"
|
#define PRIuLEAST8 "u"
|
||||||
#define PRIuLEAST16 "u"
|
#define PRIuLEAST16 "u"
|
||||||
#define PRIuLEAST32 "u"
|
#define PRIuLEAST32 "u"
|
||||||
#define PRIuLEAST64 __PRI64_RANK "u"
|
#define PRIuLEAST64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define PRIuFAST8 "u"
|
#define PRIuFAST8 "u"
|
||||||
#define PRIuFAST16 __PRIFAST_RANK "u"
|
#define PRIuFAST16 __PRIFAST_RANK "u"
|
||||||
#define PRIuFAST32 __PRIFAST_RANK "u"
|
#define PRIuFAST32 __PRIFAST_RANK "u"
|
||||||
#define PRIuFAST64 __PRI64_RANK "u"
|
#define PRIuFAST64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define PRIuMAX __PRI64_RANK "u"
|
#define PRIuMAX __PRI64_RANK "u"
|
||||||
#define PRIuPTR __PRIPTR_RANK "u"
|
#define PRIuPTR __PRIPTR_RANK "u"
|
||||||
|
|
||||||
#define PRIx8 "x"
|
#define PRIx8 "x"
|
||||||
#define PRIx16 "x"
|
#define PRIx16 "x"
|
||||||
#define PRIx32 "x"
|
#define PRIx32 "x"
|
||||||
#define PRIx64 __PRI64_RANK "x"
|
#define PRIx64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define PRIxLEAST8 "x"
|
#define PRIxLEAST8 "x"
|
||||||
#define PRIxLEAST16 "x"
|
#define PRIxLEAST16 "x"
|
||||||
#define PRIxLEAST32 "x"
|
#define PRIxLEAST32 "x"
|
||||||
#define PRIxLEAST64 __PRI64_RANK "x"
|
#define PRIxLEAST64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define PRIxFAST8 "x"
|
#define PRIxFAST8 "x"
|
||||||
#define PRIxFAST16 __PRIFAST_RANK "x"
|
#define PRIxFAST16 __PRIFAST_RANK "x"
|
||||||
#define PRIxFAST32 __PRIFAST_RANK "x"
|
#define PRIxFAST32 __PRIFAST_RANK "x"
|
||||||
#define PRIxFAST64 __PRI64_RANK "x"
|
#define PRIxFAST64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define PRIxMAX __PRI64_RANK "x"
|
#define PRIxMAX __PRI64_RANK "x"
|
||||||
#define PRIxPTR __PRIPTR_RANK "x"
|
#define PRIxPTR __PRIPTR_RANK "x"
|
||||||
|
|
||||||
#define PRIX8 "X"
|
#define PRIX8 "X"
|
||||||
#define PRIX16 "X"
|
#define PRIX16 "X"
|
||||||
#define PRIX32 "X"
|
#define PRIX32 "X"
|
||||||
#define PRIX64 __PRI64_RANK "X"
|
#define PRIX64 __PRI64_RANK "X"
|
||||||
|
|
||||||
#define PRIXLEAST8 "X"
|
#define PRIXLEAST8 "X"
|
||||||
#define PRIXLEAST16 "X"
|
#define PRIXLEAST16 "X"
|
||||||
#define PRIXLEAST32 "X"
|
#define PRIXLEAST32 "X"
|
||||||
#define PRIXLEAST64 __PRI64_RANK "X"
|
#define PRIXLEAST64 __PRI64_RANK "X"
|
||||||
|
|
||||||
#define PRIXFAST8 "X"
|
#define PRIXFAST8 "X"
|
||||||
#define PRIXFAST16 __PRIFAST_RANK "X"
|
#define PRIXFAST16 __PRIFAST_RANK "X"
|
||||||
#define PRIXFAST32 __PRIFAST_RANK "X"
|
#define PRIXFAST32 __PRIFAST_RANK "X"
|
||||||
#define PRIXFAST64 __PRI64_RANK "X"
|
#define PRIXFAST64 __PRI64_RANK "X"
|
||||||
|
|
||||||
#define PRIXMAX __PRI64_RANK "X"
|
#define PRIXMAX __PRI64_RANK "X"
|
||||||
#define PRIXPTR __PRIPTR_RANK "X"
|
#define PRIXPTR __PRIPTR_RANK "X"
|
||||||
|
|
||||||
#define SCNd8 "hhd"
|
#define SCNd8 "hhd"
|
||||||
#define SCNd16 "hd"
|
#define SCNd16 "hd"
|
||||||
#define SCNd32 "d"
|
#define SCNd32 "d"
|
||||||
#define SCNd64 __PRI64_RANK "d"
|
#define SCNd64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define SCNdLEAST8 "hhd"
|
#define SCNdLEAST8 "hhd"
|
||||||
#define SCNdLEAST16 "hd"
|
#define SCNdLEAST16 "hd"
|
||||||
#define SCNdLEAST32 "d"
|
#define SCNdLEAST32 "d"
|
||||||
#define SCNdLEAST64 __PRI64_RANK "d"
|
#define SCNdLEAST64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define SCNdFAST8 "hhd"
|
#define SCNdFAST8 "hhd"
|
||||||
#define SCNdFAST16 __PRIFAST_RANK "d"
|
#define SCNdFAST16 __PRIFAST_RANK "d"
|
||||||
#define SCNdFAST32 __PRIFAST_RANK "d"
|
#define SCNdFAST32 __PRIFAST_RANK "d"
|
||||||
#define SCNdFAST64 __PRI64_RANK "d"
|
#define SCNdFAST64 __PRI64_RANK "d"
|
||||||
|
|
||||||
#define SCNdMAX __PRI64_RANK "d"
|
#define SCNdMAX __PRI64_RANK "d"
|
||||||
#define SCNdPTR __PRIPTR_RANK "d"
|
#define SCNdPTR __PRIPTR_RANK "d"
|
||||||
|
|
||||||
#define SCNi8 "hhi"
|
#define SCNi8 "hhi"
|
||||||
#define SCNi16 "hi"
|
#define SCNi16 "hi"
|
||||||
#define SCNi32 "i"
|
#define SCNi32 "i"
|
||||||
#define SCNi64 __PRI64_RANK "i"
|
#define SCNi64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define SCNiLEAST8 "hhi"
|
#define SCNiLEAST8 "hhi"
|
||||||
#define SCNiLEAST16 "hi"
|
#define SCNiLEAST16 "hi"
|
||||||
#define SCNiLEAST32 "i"
|
#define SCNiLEAST32 "i"
|
||||||
#define SCNiLEAST64 __PRI64_RANK "i"
|
#define SCNiLEAST64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define SCNiFAST8 "hhi"
|
#define SCNiFAST8 "hhi"
|
||||||
#define SCNiFAST16 __PRIFAST_RANK "i"
|
#define SCNiFAST16 __PRIFAST_RANK "i"
|
||||||
#define SCNiFAST32 __PRIFAST_RANK "i"
|
#define SCNiFAST32 __PRIFAST_RANK "i"
|
||||||
#define SCNiFAST64 __PRI64_RANK "i"
|
#define SCNiFAST64 __PRI64_RANK "i"
|
||||||
|
|
||||||
#define SCNiMAX __PRI64_RANK "i"
|
#define SCNiMAX __PRI64_RANK "i"
|
||||||
#define SCNiPTR __PRIPTR_RANK "i"
|
#define SCNiPTR __PRIPTR_RANK "i"
|
||||||
|
|
||||||
#define SCNo8 "hho"
|
#define SCNo8 "hho"
|
||||||
#define SCNo16 "ho"
|
#define SCNo16 "ho"
|
||||||
#define SCNo32 "o"
|
#define SCNo32 "o"
|
||||||
#define SCNo64 __PRI64_RANK "o"
|
#define SCNo64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define SCNoLEAST8 "hho"
|
#define SCNoLEAST8 "hho"
|
||||||
#define SCNoLEAST16 "ho"
|
#define SCNoLEAST16 "ho"
|
||||||
#define SCNoLEAST32 "o"
|
#define SCNoLEAST32 "o"
|
||||||
#define SCNoLEAST64 __PRI64_RANK "o"
|
#define SCNoLEAST64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define SCNoFAST8 "hho"
|
#define SCNoFAST8 "hho"
|
||||||
#define SCNoFAST16 __PRIFAST_RANK "o"
|
#define SCNoFAST16 __PRIFAST_RANK "o"
|
||||||
#define SCNoFAST32 __PRIFAST_RANK "o"
|
#define SCNoFAST32 __PRIFAST_RANK "o"
|
||||||
#define SCNoFAST64 __PRI64_RANK "o"
|
#define SCNoFAST64 __PRI64_RANK "o"
|
||||||
|
|
||||||
#define SCNoMAX __PRI64_RANK "o"
|
#define SCNoMAX __PRI64_RANK "o"
|
||||||
#define SCNoPTR __PRIPTR_RANK "o"
|
#define SCNoPTR __PRIPTR_RANK "o"
|
||||||
|
|
||||||
#define SCNu8 "hhu"
|
#define SCNu8 "hhu"
|
||||||
#define SCNu16 "hu"
|
#define SCNu16 "hu"
|
||||||
#define SCNu32 "u"
|
#define SCNu32 "u"
|
||||||
#define SCNu64 __PRI64_RANK "u"
|
#define SCNu64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define SCNuLEAST8 "hhu"
|
#define SCNuLEAST8 "hhu"
|
||||||
#define SCNuLEAST16 "hu"
|
#define SCNuLEAST16 "hu"
|
||||||
#define SCNuLEAST32 "u"
|
#define SCNuLEAST32 "u"
|
||||||
#define SCNuLEAST64 __PRI64_RANK "u"
|
#define SCNuLEAST64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define SCNuFAST8 "hhu"
|
#define SCNuFAST8 "hhu"
|
||||||
#define SCNuFAST16 __PRIFAST_RANK "u"
|
#define SCNuFAST16 __PRIFAST_RANK "u"
|
||||||
#define SCNuFAST32 __PRIFAST_RANK "u"
|
#define SCNuFAST32 __PRIFAST_RANK "u"
|
||||||
#define SCNuFAST64 __PRI64_RANK "u"
|
#define SCNuFAST64 __PRI64_RANK "u"
|
||||||
|
|
||||||
#define SCNuMAX __PRI64_RANK "u"
|
#define SCNuMAX __PRI64_RANK "u"
|
||||||
#define SCNuPTR __PRIPTR_RANK "u"
|
#define SCNuPTR __PRIPTR_RANK "u"
|
||||||
|
|
||||||
#define SCNx8 "hhx"
|
#define SCNx8 "hhx"
|
||||||
#define SCNx16 "hx"
|
#define SCNx16 "hx"
|
||||||
#define SCNx32 "x"
|
#define SCNx32 "x"
|
||||||
#define SCNx64 __PRI64_RANK "x"
|
#define SCNx64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define SCNxLEAST8 "hhx"
|
#define SCNxLEAST8 "hhx"
|
||||||
#define SCNxLEAST16 "hx"
|
#define SCNxLEAST16 "hx"
|
||||||
#define SCNxLEAST32 "x"
|
#define SCNxLEAST32 "x"
|
||||||
#define SCNxLEAST64 __PRI64_RANK "x"
|
#define SCNxLEAST64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define SCNxFAST8 "hhx"
|
#define SCNxFAST8 "hhx"
|
||||||
#define SCNxFAST16 __PRIFAST_RANK "x"
|
#define SCNxFAST16 __PRIFAST_RANK "x"
|
||||||
#define SCNxFAST32 __PRIFAST_RANK "x"
|
#define SCNxFAST32 __PRIFAST_RANK "x"
|
||||||
#define SCNxFAST64 __PRI64_RANK "x"
|
#define SCNxFAST64 __PRI64_RANK "x"
|
||||||
|
|
||||||
#define SCNxMAX __PRI64_RANK "x"
|
#define SCNxMAX __PRI64_RANK "x"
|
||||||
#define SCNxPTR __PRIPTR_RANK "x"
|
#define SCNxPTR __PRIPTR_RANK "x"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _INTTYPES_H */
|
#endif /* _INTTYPES_H */
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
/* Most other C compilers have __cdecl as a keyword */
|
/* Most other C compilers have __cdecl as a keyword */
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define __cdecl /* Meaningless on non-i386 */
|
# define __cdecl /* Meaningless on non-i386 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* How to declare a function that *must* be inlined */
|
/* How to declare a function that *must* be inlined */
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
# if __GNUC__ >= 3
|
# if __GNUC__ >= 3
|
||||||
# ifdef __GNUC_STDC_INLINE__
|
# ifdef __GNUC_STDC_INLINE__
|
||||||
# define __must_inline extern __inline__ \
|
# define __must_inline extern __inline__ \
|
||||||
__attribute__((__gnu_inline__,__always_inline__))
|
__attribute__((__gnu_inline__,__always_inline__))
|
||||||
# else
|
# else
|
||||||
# define __must_inline extern __inline__ __attribute__((__always_inline__))
|
# define __must_inline extern __inline__ __attribute__((__always_inline__))
|
||||||
# endif
|
# endif
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
# define __must_inline extern __inline__
|
# define __must_inline extern __inline__
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
# define __must_inline __inline /* Just hope this works... */
|
# define __must_inline __inline /* Just hope this works... */
|
||||||
# define __inline inline
|
# define __inline inline
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
#ifndef _LIMITS_H
|
#ifndef _LIMITS_H
|
||||||
#define _LIMITS_H
|
#define _LIMITS_H
|
||||||
|
|
||||||
#define CHAR_BIT 8
|
#define CHAR_BIT 8
|
||||||
#define SHRT_BIT 16
|
#define SHRT_BIT 16
|
||||||
#define INT_BIT 32
|
#define INT_BIT 32
|
||||||
#define LONGLONG_BIT 64
|
#define LONGLONG_BIT 64
|
||||||
|
|
||||||
#define SCHAR_MIN (-128)
|
#define SCHAR_MIN (-128)
|
||||||
#define SCHAR_MAX 127
|
#define SCHAR_MAX 127
|
||||||
#define UCHAR_MAX 255
|
#define UCHAR_MAX 255
|
||||||
|
|
||||||
#ifdef __CHAR_UNSIGNED__
|
#ifdef __CHAR_UNSIGNED__
|
||||||
# define CHAR_MIN 0
|
# define CHAR_MIN 0
|
||||||
|
@ -22,22 +22,22 @@
|
||||||
# define CHAR_MAX SCHAR_MAX
|
# define CHAR_MAX SCHAR_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SHRT_MIN (-32768)
|
#define SHRT_MIN (-32768)
|
||||||
#define SHRT_MAX 32767
|
#define SHRT_MAX 32767
|
||||||
#define USHRT_MAX 65535
|
#define USHRT_MAX 65535
|
||||||
|
|
||||||
#define INT_MIN (-2147483647-1)
|
#define INT_MIN (-2147483647-1)
|
||||||
#define INT_MAX 2147483647
|
#define INT_MAX 2147483647
|
||||||
#define UINT_MAX 4294967295U
|
#define UINT_MAX 4294967295U
|
||||||
|
|
||||||
#define LONGLONG_MIN (-9223372036854775807LL-1)
|
#define LONGLONG_MIN (-9223372036854775807LL-1)
|
||||||
#define LONGLONG_MAX 9223372036854775807LL
|
#define LONGLONG_MAX 9223372036854775807LL
|
||||||
#define ULONGLONG_MAX 18446744073709551615ULL
|
#define ULONGLONG_MAX 18446744073709551615ULL
|
||||||
|
|
||||||
#define LONG_BIT 32
|
#define LONG_BIT 32
|
||||||
|
|
||||||
#define LONG_MIN (-2147483647L-1)
|
#define LONG_MIN (-2147483647L-1)
|
||||||
#define LONG_MAX 2147483647L
|
#define LONG_MAX 2147483647L
|
||||||
#define ULONG_MAX 4294967295UL
|
#define ULONG_MAX 4294967295UL
|
||||||
|
|
||||||
#endif /* _LIMITS_H */
|
#endif /* _LIMITS_H */
|
||||||
|
|
|
@ -9,4 +9,4 @@
|
||||||
#define true 1
|
#define true 1
|
||||||
#define false 0
|
#define false 0
|
||||||
|
|
||||||
#endif /* _STDBOOL_H */
|
#endif /* _STDBOOL_H */
|
||||||
|
|
|
@ -26,4 +26,4 @@ typedef signed int wint_t;
|
||||||
#undef offsetof
|
#undef offsetof
|
||||||
#define offsetof(t,m) ((size_t)&((t *)0)->m)
|
#define offsetof(t,m) ((size_t)&((t *)0)->m)
|
||||||
|
|
||||||
#endif /* _STDDEF_H */
|
#endif /* _STDDEF_H */
|
||||||
|
|
|
@ -5,24 +5,24 @@
|
||||||
#ifndef _STDINT_H
|
#ifndef _STDINT_H
|
||||||
#define _STDINT_H
|
#define _STDINT_H
|
||||||
|
|
||||||
typedef signed char int8_t;
|
typedef signed char int8_t;
|
||||||
typedef short int int16_t;
|
typedef short int int16_t;
|
||||||
typedef int int32_t;
|
typedef int int32_t;
|
||||||
typedef long long int int64_t;
|
typedef long long int int64_t;
|
||||||
|
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
typedef unsigned short int uint16_t;
|
typedef unsigned short int uint16_t;
|
||||||
typedef unsigned int uint32_t;
|
typedef unsigned int uint32_t;
|
||||||
typedef unsigned long long int uint64_t;
|
typedef unsigned long long int uint64_t;
|
||||||
|
|
||||||
typedef int int_fast16_t;
|
typedef int int_fast16_t;
|
||||||
typedef int int_fast32_t;
|
typedef int int_fast32_t;
|
||||||
|
|
||||||
typedef unsigned int uint_fast16_t;
|
typedef unsigned int uint_fast16_t;
|
||||||
typedef unsigned int uint_fast32_t;
|
typedef unsigned int uint_fast32_t;
|
||||||
|
|
||||||
typedef int intptr_t;
|
typedef int intptr_t;
|
||||||
typedef unsigned int uintptr_t;
|
typedef unsigned int uintptr_t;
|
||||||
|
|
||||||
#define __INT64_C(c) c ## LL
|
#define __INT64_C(c) c ## LL
|
||||||
#define __UINT64_C(c) c ## ULL
|
#define __UINT64_C(c) c ## ULL
|
||||||
|
@ -30,99 +30,99 @@ typedef unsigned int uintptr_t;
|
||||||
#define __PRI64_RANK "ll"
|
#define __PRI64_RANK "ll"
|
||||||
#define __PRIFAST_RANK ""
|
#define __PRIFAST_RANK ""
|
||||||
#define __PRIPTR_RANK ""
|
#define __PRIPTR_RANK ""
|
||||||
typedef int8_t int_least8_t;
|
typedef int8_t int_least8_t;
|
||||||
typedef int16_t int_least16_t;
|
typedef int16_t int_least16_t;
|
||||||
typedef int32_t int_least32_t;
|
typedef int32_t int_least32_t;
|
||||||
typedef int64_t int_least64_t;
|
typedef int64_t int_least64_t;
|
||||||
|
|
||||||
typedef uint8_t uint_least8_t;
|
typedef uint8_t uint_least8_t;
|
||||||
typedef uint16_t uint_least16_t;
|
typedef uint16_t uint_least16_t;
|
||||||
typedef uint32_t uint_least32_t;
|
typedef uint32_t uint_least32_t;
|
||||||
typedef uint64_t uint_least64_t;
|
typedef uint64_t uint_least64_t;
|
||||||
|
|
||||||
typedef int8_t int_fast8_t;
|
typedef int8_t int_fast8_t;
|
||||||
typedef int64_t int_fast64_t;
|
typedef int64_t int_fast64_t;
|
||||||
|
|
||||||
typedef uint8_t uint_fast8_t;
|
typedef uint8_t uint_fast8_t;
|
||||||
typedef uint64_t uint_fast64_t;
|
typedef uint64_t uint_fast64_t;
|
||||||
|
|
||||||
typedef int64_t intmax_t;
|
typedef int64_t intmax_t;
|
||||||
typedef uint64_t uintmax_t;
|
typedef uint64_t uintmax_t;
|
||||||
|
|
||||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
|
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
|
||||||
|
|
||||||
#define INT8_MIN (-128)
|
#define INT8_MIN (-128)
|
||||||
#define INT16_MIN (-32768)
|
#define INT16_MIN (-32768)
|
||||||
#define INT32_MIN (-2147483647-1)
|
#define INT32_MIN (-2147483647-1)
|
||||||
#define INT64_MIN (__INT64_C(-9223372036854775807)-1)
|
#define INT64_MIN (__INT64_C(-9223372036854775807)-1)
|
||||||
|
|
||||||
#define INT8_MAX (127)
|
#define INT8_MAX (127)
|
||||||
#define INT16_MAX (32767)
|
#define INT16_MAX (32767)
|
||||||
#define INT32_MAX (2147483647)
|
#define INT32_MAX (2147483647)
|
||||||
#define INT64_MAX (__INT64_C(9223372036854775807))
|
#define INT64_MAX (__INT64_C(9223372036854775807))
|
||||||
|
|
||||||
#define UINT8_MAX (255U)
|
#define UINT8_MAX (255U)
|
||||||
#define UINT16_MAX (65535U)
|
#define UINT16_MAX (65535U)
|
||||||
#define UINT32_MAX (4294967295U)
|
#define UINT32_MAX (4294967295U)
|
||||||
#define UINT64_MAX (__UINT64_C(18446744073709551615))
|
#define UINT64_MAX (__UINT64_C(18446744073709551615))
|
||||||
|
|
||||||
#define INT_LEAST8_MIN INT8_MIN
|
#define INT_LEAST8_MIN INT8_MIN
|
||||||
#define INT_LEAST16_MIN INT16_MIN
|
#define INT_LEAST16_MIN INT16_MIN
|
||||||
#define INT_LEAST32_MIN INT32_MIN
|
#define INT_LEAST32_MIN INT32_MIN
|
||||||
#define INT_LEAST64_MIN INT64_MIN
|
#define INT_LEAST64_MIN INT64_MIN
|
||||||
|
|
||||||
#define INT_LEAST8_MAX INT8_MAX
|
#define INT_LEAST8_MAX INT8_MAX
|
||||||
#define INT_LEAST16_MAX INT16_MAX
|
#define INT_LEAST16_MAX INT16_MAX
|
||||||
#define INT_LEAST32_MAX INT32_MAX
|
#define INT_LEAST32_MAX INT32_MAX
|
||||||
#define INT_LEAST64_MAX INT64_MAX
|
#define INT_LEAST64_MAX INT64_MAX
|
||||||
|
|
||||||
#define UINT_LEAST8_MAX UINT8_MAX
|
#define UINT_LEAST8_MAX UINT8_MAX
|
||||||
#define UINT_LEAST16_MAX UINT16_MAX
|
#define UINT_LEAST16_MAX UINT16_MAX
|
||||||
#define UINT_LEAST32_MAX UINT32_MAX
|
#define UINT_LEAST32_MAX UINT32_MAX
|
||||||
#define UINT_LEAST64_MAX UINT64_MAX
|
#define UINT_LEAST64_MAX UINT64_MAX
|
||||||
|
|
||||||
#define INT_FAST8_MIN INT8_MIN
|
#define INT_FAST8_MIN INT8_MIN
|
||||||
#define INT_FAST64_MIN INT64_MIN
|
#define INT_FAST64_MIN INT64_MIN
|
||||||
|
|
||||||
#define INT_FAST8_MAX INT8_MAX
|
#define INT_FAST8_MAX INT8_MAX
|
||||||
#define INT_FAST64_MAX INT64_MAX
|
#define INT_FAST64_MAX INT64_MAX
|
||||||
|
|
||||||
#define UINT_FAST8_MAX UINT8_MAX
|
#define UINT_FAST8_MAX UINT8_MAX
|
||||||
#define UINT_FAST64_MAX UINT64_MAX
|
#define UINT_FAST64_MAX UINT64_MAX
|
||||||
|
|
||||||
#define INTMAX_MIN INT64_MIN
|
#define INTMAX_MIN INT64_MIN
|
||||||
#define INTMAX_MAX INT64_MAX
|
#define INTMAX_MAX INT64_MAX
|
||||||
#define UINTMAX_MAX UINT64_MAX
|
#define UINTMAX_MAX UINT64_MAX
|
||||||
|
|
||||||
#define INT_FAST16_MIN INT32_MIN
|
#define INT_FAST16_MIN INT32_MIN
|
||||||
#define INT_FAST32_MIN INT32_MIN
|
#define INT_FAST32_MIN INT32_MIN
|
||||||
#define INT_FAST16_MAX INT32_MAX
|
#define INT_FAST16_MAX INT32_MAX
|
||||||
#define INT_FAST32_MAX INT32_MAX
|
#define INT_FAST32_MAX INT32_MAX
|
||||||
#define UINT_FAST16_MAX UINT32_MAX
|
#define UINT_FAST16_MAX UINT32_MAX
|
||||||
#define UINT_FAST32_MAX UINT32_MAX
|
#define UINT_FAST32_MAX UINT32_MAX
|
||||||
|
|
||||||
#define INTPTR_MIN INT32_MIN
|
#define INTPTR_MIN INT32_MIN
|
||||||
#define INTPTR_MAX INT32_MAX
|
#define INTPTR_MAX INT32_MAX
|
||||||
#define UINTPTR_MAX UINT32_MAX
|
#define UINTPTR_MAX UINT32_MAX
|
||||||
|
|
||||||
#define PTRDIFF_MIN INT32_MIN
|
#define PTRDIFF_MIN INT32_MIN
|
||||||
#define PTRDIFF_MAX INT32_MAX
|
#define PTRDIFF_MAX INT32_MAX
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
|
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
|
||||||
|
|
||||||
#define INT8_C(c) c
|
#define INT8_C(c) c
|
||||||
#define INT16_C(c) c
|
#define INT16_C(c) c
|
||||||
#define INT32_C(c) c
|
#define INT32_C(c) c
|
||||||
#define INT64_C(c) __INT64_C(c)
|
#define INT64_C(c) __INT64_C(c)
|
||||||
|
|
||||||
#define UINT8_C(c) c ## U
|
#define UINT8_C(c) c ## U
|
||||||
#define UINT16_C(c) c ## U
|
#define UINT16_C(c) c ## U
|
||||||
#define UINT32_C(c) c ## U
|
#define UINT32_C(c) c ## U
|
||||||
#define UINT64_C(c) __UINT64_C(c)
|
#define UINT64_C(c) __UINT64_C(c)
|
||||||
|
|
||||||
#define INT_LEAST8_C(c) INT8_C(c)
|
#define INT_LEAST8_C(c) INT8_C(c)
|
||||||
#define INT_LEAST16_C(c) INT16_C(c)
|
#define INT_LEAST16_C(c) INT16_C(c)
|
||||||
#define INT_LEAST32_C(c) INT32_C(c)
|
#define INT_LEAST32_C(c) INT32_C(c)
|
||||||
#define INT_LEAST64_C(c) INT64_C(c)
|
#define INT_LEAST64_C(c) INT64_C(c)
|
||||||
|
@ -132,25 +132,25 @@ typedef uint64_t uintmax_t;
|
||||||
#define UINT_LEAST32_C(c) UINT32_C(c)
|
#define UINT_LEAST32_C(c) UINT32_C(c)
|
||||||
#define UINT_LEAST64_C(c) UINT64_C(c)
|
#define UINT_LEAST64_C(c) UINT64_C(c)
|
||||||
|
|
||||||
#define INT_FAST8_C(c) INT8_C(c)
|
#define INT_FAST8_C(c) INT8_C(c)
|
||||||
#define INT_FAST64_C(c) INT64_C(c)
|
#define INT_FAST64_C(c) INT64_C(c)
|
||||||
|
|
||||||
#define UINT_FAST8_C(c) UINT8_C(c)
|
#define UINT_FAST8_C(c) UINT8_C(c)
|
||||||
#define UINT_FAST64_C(c) UINT64_C(c)
|
#define UINT_FAST64_C(c) UINT64_C(c)
|
||||||
|
|
||||||
#define INTMAX_C(c) INT64_C(c)
|
#define INTMAX_C(c) INT64_C(c)
|
||||||
#define UINTMAX_C(c) UINT64_C(c)
|
#define UINTMAX_C(c) UINT64_C(c)
|
||||||
|
|
||||||
#define INT_FAST16_C(c) INT32_C(c)
|
#define INT_FAST16_C(c) INT32_C(c)
|
||||||
#define INT_FAST32_C(c) INT32_C(c)
|
#define INT_FAST32_C(c) INT32_C(c)
|
||||||
|
|
||||||
#define UINT_FAST16_C(c) UINT32_C(c)
|
#define UINT_FAST16_C(c) UINT32_C(c)
|
||||||
#define UINT_FAST32_C(c) UINT32_C(c)
|
#define UINT_FAST32_C(c) UINT32_C(c)
|
||||||
|
|
||||||
#define INTPTR_C(c) INT32_C(c)
|
#define INTPTR_C(c) INT32_C(c)
|
||||||
#define UINTPTR_C(c) UINT32_C(c)
|
#define UINTPTR_C(c) UINT32_C(c)
|
||||||
#define PTRDIFF_C(c) INT32_C(c)
|
#define PTRDIFF_C(c) INT32_C(c)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _STDINT_H */
|
#endif /* _STDINT_H */
|
||||||
|
|
|
@ -18,4 +18,4 @@ __extern int vsnprintf(char *, size_t n, const char *, va_list);
|
||||||
__extern int sscanf(const char *, const char *, ...);
|
__extern int sscanf(const char *, const char *, ...);
|
||||||
__extern int vsscanf(const char *, const char *, va_list);
|
__extern int vsscanf(const char *, const char *, va_list);
|
||||||
|
|
||||||
#endif /* _STDIO_H */
|
#endif /* _STDIO_H */
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
static __inline int abs(int __n)
|
static __inline int abs(int __n)
|
||||||
{
|
{
|
||||||
return (__n < 0) ? -__n : __n;
|
return (__n < 0) ? -__n : __n;
|
||||||
}
|
}
|
||||||
__extern int atoi(const char *);
|
__extern int atoi(const char *);
|
||||||
__extern double atof(const char *);
|
__extern double atof(const char *);
|
||||||
|
@ -22,12 +22,12 @@ __extern long atol(const char *);
|
||||||
__extern long long atoll(const char *);
|
__extern long long atoll(const char *);
|
||||||
static __inline long labs(long __n)
|
static __inline long labs(long __n)
|
||||||
{
|
{
|
||||||
return (__n < 0L) ? -__n : __n;
|
return (__n < 0L) ? -__n : __n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline long long llabs(long long __n)
|
static __inline long long llabs(long long __n)
|
||||||
{
|
{
|
||||||
return (__n < 0LL) ? -__n : __n;
|
return (__n < 0LL) ? -__n : __n;
|
||||||
}
|
}
|
||||||
|
|
||||||
__extern long strtol(const char *, char **, int);
|
__extern long strtol(const char *, char **, int);
|
||||||
|
@ -37,7 +37,7 @@ __extern unsigned long long strtoull(const char *, char **, int);
|
||||||
|
|
||||||
typedef int (*__comparefunc_t) (const void *, const void *);
|
typedef int (*__comparefunc_t) (const void *, const void *);
|
||||||
__extern void *bsearch(const void *, const void *, size_t, size_t,
|
__extern void *bsearch(const void *, const void *, size_t, size_t,
|
||||||
__comparefunc_t);
|
__comparefunc_t);
|
||||||
__extern void qsort(void *, size_t, size_t, __comparefunc_t);
|
__extern void qsort(void *, size_t, size_t, __comparefunc_t);
|
||||||
|
|
||||||
__extern long jrand48(unsigned short *);
|
__extern long jrand48(unsigned short *);
|
||||||
|
@ -53,4 +53,4 @@ __extern void srand(unsigned int __s);
|
||||||
__extern long random(void);
|
__extern long random(void);
|
||||||
__extern void srandom(unsigned int __s);
|
__extern void srandom(unsigned int __s);
|
||||||
|
|
||||||
#endif /* _STDLIB_H */
|
#endif /* _STDLIB_H */
|
||||||
|
|
|
@ -41,4 +41,4 @@ __extern char *strtok(char *, const char *);
|
||||||
__extern char *strtok_r(char *, const char *, char **);
|
__extern char *strtok_r(char *, const char *, char **);
|
||||||
char *index(const char *s, int c);
|
char *index(const char *s, int c);
|
||||||
|
|
||||||
#endif /* _STRING_H */
|
#endif /* _STRING_H */
|
||||||
|
|
|
@ -81,13 +81,13 @@ typedef unsigned long useconds_t;
|
||||||
#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
|
#define FD_ZERO(p) memset((void *)(p), 0, sizeof(*(p)))
|
||||||
|
|
||||||
typedef struct fd_set {
|
typedef struct fd_set {
|
||||||
unsigned char fd_bits[(FD_SETSIZE + 7) / 8];
|
unsigned char fd_bits[(FD_SETSIZE + 7) / 8];
|
||||||
} fd_set;
|
} fd_set;
|
||||||
#endif /* FD_SET */
|
#endif /* FD_SET */
|
||||||
|
|
||||||
#ifndef __ICCARM__
|
#ifndef __ICCARM__
|
||||||
/* wmsdk: Added from sys/times.h and machine/types.h */
|
/* wmsdk: Added from sys/times.h and machine/types.h */
|
||||||
#define _CLOCK_T_ unsigned long /* clock() */
|
#define _CLOCK_T_ unsigned long /* clock() */
|
||||||
#ifndef __clock_t_defined
|
#ifndef __clock_t_defined
|
||||||
typedef _CLOCK_T_ clock_t;
|
typedef _CLOCK_T_ clock_t;
|
||||||
#define __clock_t_defined
|
#define __clock_t_defined
|
||||||
|
|
|
@ -16,87 +16,87 @@
|
||||||
|
|
||||||
static inline int digitval(int ch)
|
static inline int digitval(int ch)
|
||||||
{
|
{
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
return ch - '0';
|
return ch - '0';
|
||||||
} else if (ch >= 'A' && ch <= 'Z') {
|
} else if (ch >= 'A' && ch <= 'Z') {
|
||||||
return ch - 'A' + 10;
|
return ch - 'A' + 10;
|
||||||
} else if (ch >= 'a' && ch <= 'z') {
|
} else if (ch >= 'a' && ch <= 'z') {
|
||||||
return ch - 'a' + 10;
|
return ch - 'a' + 10;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double strntof(const char *nptr, char **endptr, int base, size_t n)
|
double strntof(const char *nptr, char **endptr, int base, size_t n)
|
||||||
{
|
{
|
||||||
int minus = 0;
|
int minus = 0;
|
||||||
double v = 0.0, m = 0.0, divisor = 1.0;
|
double v = 0.0, m = 0.0, divisor = 1.0;
|
||||||
int d;
|
int d;
|
||||||
|
|
||||||
while (n && isspace((unsigned char)*nptr)) {
|
while (n && isspace((unsigned char)*nptr)) {
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Single optional + or - */
|
/* Single optional + or - */
|
||||||
if (n) {
|
if (n) {
|
||||||
char c = *nptr;
|
char c = *nptr;
|
||||||
if (c == '-' || c == '+') {
|
if (c == '-' || c == '+') {
|
||||||
minus = (c == '-');
|
minus = (c == '-');
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
} else if (n >= 1 && nptr[0] == '0') {
|
} else if (n >= 1 && nptr[0] == '0') {
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
base = 8;
|
base = 8;
|
||||||
} else {
|
} else {
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
} else if (base == 16) {
|
} else if (base == 16) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
||||||
v = v * base + d;
|
v = v * base + d;
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*nptr == '.') {
|
if (*nptr == '.') {
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
||||||
m = m * base + d;
|
m = m * base + d;
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
divisor *= 10.0;
|
divisor *= 10.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endptr)
|
if (endptr)
|
||||||
*endptr = (char *)nptr;
|
*endptr = (char *)nptr;
|
||||||
|
|
||||||
v = v + (m / divisor);
|
v = v + (m / divisor);
|
||||||
|
|
||||||
return minus ? -v : v;
|
return minus ? -v : v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double atof(const char *nptr)
|
double atof(const char *nptr)
|
||||||
{
|
{
|
||||||
return strntof(nptr, NULL, 0, strlen(nptr));
|
return strntof(nptr, NULL, 0, strlen(nptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,5 @@
|
||||||
|
|
||||||
TYPE NAME(const char *nptr)
|
TYPE NAME(const char *nptr)
|
||||||
{
|
{
|
||||||
return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
|
return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,23 +9,23 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void *bsearch(const void *key, const void *base, size_t nmemb,
|
void *bsearch(const void *key, const void *base, size_t nmemb,
|
||||||
size_t size, int (*cmp) (const void *, const void *))
|
size_t size, int (*cmp) (const void *, const void *))
|
||||||
{
|
{
|
||||||
while (nmemb) {
|
while (nmemb) {
|
||||||
size_t mididx = nmemb / 2;
|
size_t mididx = nmemb / 2;
|
||||||
const void *midobj = (const unsigned char *) base +
|
const void *midobj = (const unsigned char *) base +
|
||||||
mididx * size;
|
mididx * size;
|
||||||
int diff = cmp(key, midobj);
|
int diff = cmp(key, midobj);
|
||||||
|
|
||||||
if (diff == 0)
|
if (diff == 0)
|
||||||
return (void *)midobj;
|
return (void *)midobj;
|
||||||
|
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
base = (const unsigned char *) midobj + size;
|
base = (const unsigned char *) midobj + size;
|
||||||
nmemb -= mididx + 1;
|
nmemb -= mididx + 1;
|
||||||
} else
|
} else
|
||||||
nmemb = mididx;
|
nmemb = mididx;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,21 +5,21 @@
|
||||||
//#include <stdio.h>
|
//#include <stdio.h>
|
||||||
|
|
||||||
void __assert_func(const char *file, int line,
|
void __assert_func(const char *file, int line,
|
||||||
const char *func, const char *failedexpr)
|
const char *func, const char *failedexpr)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
|
||||||
failedexpr, file, line, func ? ", function: " : "",
|
failedexpr, file, line, func ? ", function: " : "",
|
||||||
func ? func : "");
|
func ? func : "");
|
||||||
|
|
||||||
/* Ensure that nothing runs after this */
|
/* Ensure that nothing runs after this */
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float strtof(const char *nptr, char **endptr)
|
float strtof(const char *nptr, char **endptr)
|
||||||
{
|
{
|
||||||
// printf("Float print not supported yet!\r\n");
|
// printf("Float print not supported yet!\r\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#define __CTYPE_NO_INLINE
|
#define __CTYPE_NO_INLINE
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#define CTYPEFUNC(X) \
|
#define CTYPEFUNC(X) \
|
||||||
int X(int c) { \
|
int X(int c) { \
|
||||||
return __ctype_##X(c); \
|
return __ctype_##X(c); \
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,277 +12,277 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
const unsigned char __ctypes[257] = {
|
const unsigned char __ctypes[257] = {
|
||||||
0, /* EOF */
|
0, /* EOF */
|
||||||
|
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl | __ctype_space, /* BS */
|
__ctype_cntrl | __ctype_space, /* BS */
|
||||||
__ctype_cntrl | __ctype_space, /* TAB */
|
__ctype_cntrl | __ctype_space, /* TAB */
|
||||||
__ctype_cntrl | __ctype_space, /* LF */
|
__ctype_cntrl | __ctype_space, /* LF */
|
||||||
__ctype_cntrl | __ctype_space, /* VT */
|
__ctype_cntrl | __ctype_space, /* VT */
|
||||||
__ctype_cntrl | __ctype_space, /* FF */
|
__ctype_cntrl | __ctype_space, /* FF */
|
||||||
__ctype_cntrl | __ctype_space, /* CR */
|
__ctype_cntrl | __ctype_space, /* CR */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
|
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
|
|
||||||
__ctype_print | __ctype_space, /* space */
|
__ctype_print | __ctype_space, /* space */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
|
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
__ctype_print | __ctype_digit | __ctype_xdigit, /* digit */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
|
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
__ctype_print | __ctype_upper | __ctype_xdigit, /* A-F */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
|
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_upper, /* G-Z */
|
__ctype_print | __ctype_upper, /* G-Z */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
|
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
__ctype_print | __ctype_lower | __ctype_xdigit, /* a-f */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
|
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_lower, /* g-z */
|
__ctype_print | __ctype_lower, /* g-z */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
|
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
|
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
__ctype_cntrl, /* control character */
|
__ctype_cntrl, /* control character */
|
||||||
|
|
||||||
__ctype_print | __ctype_space, /* NBSP */
|
__ctype_print | __ctype_space, /* NBSP */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
|
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
|
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
|
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_upper, /* upper accented */
|
__ctype_print | __ctype_upper, /* upper accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
|
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
|
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_punct, /* punctuation */
|
__ctype_print | __ctype_punct, /* punctuation */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
__ctype_print | __ctype_lower, /* lower accented */
|
__ctype_print | __ctype_lower, /* lower accented */
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,65 +12,65 @@
|
||||||
|
|
||||||
int fnmatch(const char *p, const char *s, int flags)
|
int fnmatch(const char *p, const char *s, int flags)
|
||||||
{
|
{
|
||||||
if (flags & FNM_PATHNAME && *s == '/')
|
if (flags & FNM_PATHNAME && *s == '/')
|
||||||
return (*p != '/') || fnmatch(p+1, s+1, flags);
|
return (*p != '/') || fnmatch(p+1, s+1, flags);
|
||||||
if (flags & FNM_PERIOD && *s == '.')
|
if (flags & FNM_PERIOD && *s == '.')
|
||||||
return (*p != '.') || fnmatch(p+1, s+1, flags);
|
return (*p != '.') || fnmatch(p+1, s+1, flags);
|
||||||
|
|
||||||
flags &= ~FNM_PERIOD; /* Only applies at beginning */
|
flags &= ~FNM_PERIOD; /* Only applies at beginning */
|
||||||
|
|
||||||
if (!(flags & FNM_NOESCAPE) && *p == '\\') {
|
if (!(flags & FNM_NOESCAPE) && *p == '\\') {
|
||||||
p++;
|
p++;
|
||||||
return (*p != *s) || fnmatch(p+1, s+1, flags);
|
return (*p != *s) || fnmatch(p+1, s+1, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*s == '\0') {
|
if (*s == '\0') {
|
||||||
while (*p == '*')
|
while (*p == '*')
|
||||||
p++;
|
p++;
|
||||||
return (*p != '\0');
|
return (*p != '\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '[':
|
case '[':
|
||||||
{
|
{
|
||||||
int not = 0;
|
int not = 0;
|
||||||
p++;
|
p++;
|
||||||
if (*p == '!') {
|
if (*p == '!') {
|
||||||
not = 1;
|
not = 1;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
while ((*p != '\0') && (*p != ']')) {
|
while ((*p != '\0') && (*p != ']')) {
|
||||||
int match = 0;
|
int match = 0;
|
||||||
if (p[1] == '-') {
|
if (p[1] == '-') {
|
||||||
if ((*s >= *p) && (*s <= p[2]))
|
if ((*s >= *p) && (*s <= p[2]))
|
||||||
match = 1;
|
match = 1;
|
||||||
p += 3;
|
p += 3;
|
||||||
} else {
|
} else {
|
||||||
match = (*p == *s);
|
match = (*p == *s);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if (match ^ not) {
|
if (match ^ not) {
|
||||||
while ((*p != '\0') && (*p != ']'))
|
while ((*p != '\0') && (*p != ']'))
|
||||||
p++;
|
p++;
|
||||||
if (*p == ']')
|
if (*p == ']')
|
||||||
return fnmatch(p+1, s+1, flags);
|
return fnmatch(p+1, s+1, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
if (fnmatch(p, s+1, flags))
|
if (fnmatch(p, s+1, flags))
|
||||||
return fnmatch(p+1, s, flags);
|
return fnmatch(p+1, s, flags);
|
||||||
return 0;
|
return 0;
|
||||||
case '\0':
|
case '\0':
|
||||||
if (*s == '\0') {
|
if (*s == '\0') {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ((*p == *s) || (*p == '?'))
|
if ((*p == *s) || (*p == '?'))
|
||||||
return fnmatch(p+1, s+1, flags);
|
return fnmatch(p+1, s+1, flags);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@
|
||||||
|
|
||||||
long jrand48(unsigned short xsubi[3])
|
long jrand48(unsigned short xsubi[3])
|
||||||
{
|
{
|
||||||
uint64_t x;
|
uint64_t x;
|
||||||
|
|
||||||
/* The xsubi[] array is littleendian by spec */
|
/* The xsubi[] array is littleendian by spec */
|
||||||
x = (uint64_t) (uint16_t) xsubi[0] +
|
x = (uint64_t) (uint16_t) xsubi[0] +
|
||||||
((uint64_t) (uint16_t) xsubi[1] << 16) +
|
((uint64_t) (uint16_t) xsubi[1] << 16) +
|
||||||
((uint64_t) (uint16_t) xsubi[2] << 32);
|
((uint64_t) (uint16_t) xsubi[2] << 32);
|
||||||
|
|
||||||
x = (0x5deece66dULL * x) + 0xb;
|
x = (0x5deece66dULL * x) + 0xb;
|
||||||
|
|
||||||
xsubi[0] = (unsigned short)(uint16_t) x;
|
xsubi[0] = (unsigned short)(uint16_t) x;
|
||||||
xsubi[1] = (unsigned short)(uint16_t) (x >> 16);
|
xsubi[1] = (unsigned short)(uint16_t) (x >> 16);
|
||||||
xsubi[2] = (unsigned short)(uint16_t) (x >> 32);
|
xsubi[2] = (unsigned short)(uint16_t) (x >> 32);
|
||||||
|
|
||||||
return (long)(int32_t) (x >> 16);
|
return (long)(int32_t) (x >> 16);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,19 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
unsigned short __rand48_seed[3]; /* Common with mrand48.c, srand48.c */
|
unsigned short __rand48_seed[3]; /* Common with mrand48.c, srand48.c */
|
||||||
|
|
||||||
long lrand48(void)
|
long lrand48(void)
|
||||||
{
|
{
|
||||||
return (uint32_t) jrand48(__rand48_seed) >> 1;
|
return (uint32_t) jrand48(__rand48_seed) >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rand(void)
|
int rand(void)
|
||||||
{
|
{
|
||||||
return (int)lrand48();
|
return (int)lrand48();
|
||||||
}
|
}
|
||||||
|
|
||||||
long random(void)
|
long random(void)
|
||||||
{
|
{
|
||||||
return lrand48();
|
return lrand48();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
|
|
||||||
void *memccpy(void *dst, const void *src, int c, size_t n)
|
void *memccpy(void *dst, const void *src, int c, size_t n)
|
||||||
{
|
{
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
*q++ = ch = *p++;
|
*q++ = ch = *p++;
|
||||||
if (ch == (char)c)
|
if (ch == (char)c)
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL; /* No instance of "c" found */
|
return NULL; /* No instance of "c" found */
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
|
|
||||||
void *memchr(const void *s, int c, size_t n)
|
void *memchr(const void *s, int c, size_t n)
|
||||||
{
|
{
|
||||||
const unsigned char *sp = s;
|
const unsigned char *sp = s;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
if (*sp == (unsigned char)c)
|
if (*sp == (unsigned char)c)
|
||||||
return (void *)sp;
|
return (void *)sp;
|
||||||
sp++;
|
sp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
|
|
||||||
int memcmp(const void *s1, const void *s2, size_t n)
|
int memcmp(const void *s1, const void *s2, size_t n)
|
||||||
{
|
{
|
||||||
const unsigned char *c1 = s1, *c2 = s2;
|
const unsigned char *c1 = s1, *c2 = s2;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
d = (int)*c1++ - (int)*c2++;
|
d = (int)*c1++ - (int)*c2++;
|
||||||
if (d)
|
if (d)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
void *memcpy(void *dst, const void *src, size_t n)
|
void *memcpy(void *dst, const void *src, size_t n)
|
||||||
{
|
{
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
while (n--) {
|
while (n--) {
|
||||||
*q++ = *p++;
|
*q++ = *p++;
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,40 +17,40 @@
|
||||||
|
|
||||||
void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
|
void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
|
||||||
{
|
{
|
||||||
const unsigned char *y = (const unsigned char *)haystack;
|
const unsigned char *y = (const unsigned char *)haystack;
|
||||||
const unsigned char *x = (const unsigned char *)needle;
|
const unsigned char *x = (const unsigned char *)needle;
|
||||||
|
|
||||||
size_t j, k, l;
|
size_t j, k, l;
|
||||||
|
|
||||||
if (m > n || !m || !n)
|
if (m > n || !m || !n)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (1 != m) {
|
if (1 != m) {
|
||||||
if (x[0] == x[1]) {
|
if (x[0] == x[1]) {
|
||||||
k = 2;
|
k = 2;
|
||||||
l = 1;
|
l = 1;
|
||||||
} else {
|
} else {
|
||||||
k = 1;
|
k = 1;
|
||||||
l = 2;
|
l = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
j = 0;
|
j = 0;
|
||||||
while (j <= n - m) {
|
while (j <= n - m) {
|
||||||
if (x[1] != y[j + 1]) {
|
if (x[1] != y[j + 1]) {
|
||||||
j += k;
|
j += k;
|
||||||
} else {
|
} else {
|
||||||
if (!memcmp(x + 2, y + j + 2, m - 2)
|
if (!memcmp(x + 2, y + j + 2, m - 2)
|
||||||
&& x[0] == y[j])
|
&& x[0] == y[j])
|
||||||
return (void *)&y[j];
|
return (void *)&y[j];
|
||||||
j += l;
|
j += l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
do {
|
do {
|
||||||
if (*y == *x)
|
if (*y == *x)
|
||||||
return (void *)y;
|
return (void *)y;
|
||||||
y++;
|
y++;
|
||||||
} while (--n);
|
} while (--n);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
|
|
||||||
void *memrchr(const void *s, int c, size_t n)
|
void *memrchr(const void *s, int c, size_t n)
|
||||||
{
|
{
|
||||||
const unsigned char *sp = (const unsigned char *)s + n - 1;
|
const unsigned char *sp = (const unsigned char *)s + n - 1;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
if (*sp == (unsigned char)c)
|
if (*sp == (unsigned char)c)
|
||||||
return (void *)sp;
|
return (void *)sp;
|
||||||
sp--;
|
sp--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
void *memset(void *dst, int c, size_t n)
|
void *memset(void *dst, int c, size_t n)
|
||||||
{
|
{
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
while (n--) {
|
while (n--) {
|
||||||
*q++ = c;
|
*q++ = c;
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,16 @@
|
||||||
|
|
||||||
void memswap(void *m1, void *m2, size_t n)
|
void memswap(void *m1, void *m2, size_t n)
|
||||||
{
|
{
|
||||||
char *p = m1;
|
char *p = m1;
|
||||||
char *q = m2;
|
char *q = m2;
|
||||||
char tmp;
|
char tmp;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
tmp = *p;
|
tmp = *p;
|
||||||
*p = *q;
|
*p = *q;
|
||||||
*q = tmp;
|
*q = tmp;
|
||||||
|
|
||||||
p++;
|
p++;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@ extern unsigned short __rand48_seed[3];
|
||||||
|
|
||||||
long mrand48(void)
|
long mrand48(void)
|
||||||
{
|
{
|
||||||
return jrand48(__rand48_seed);
|
return jrand48(__rand48_seed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
|
|
||||||
long nrand48(unsigned short xsubi[3])
|
long nrand48(unsigned short xsubi[3])
|
||||||
{
|
{
|
||||||
return (long)((uint32_t) jrand48(xsubi) >> 1);
|
return (long)((uint32_t) jrand48(xsubi) >> 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,36 +16,36 @@
|
||||||
|
|
||||||
static __inline size_t newgap(size_t gap)
|
static __inline size_t newgap(size_t gap)
|
||||||
{
|
{
|
||||||
gap = (gap * 10) / 13;
|
gap = (gap * 10) / 13;
|
||||||
if (gap == 9 || gap == 10)
|
if (gap == 9 || gap == 10)
|
||||||
gap = 11;
|
gap = 11;
|
||||||
|
|
||||||
if (gap < 1)
|
if (gap < 1)
|
||||||
gap = 1;
|
gap = 1;
|
||||||
return gap;
|
return gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qsort(void *base, size_t nmemb, size_t size,
|
void qsort(void *base, size_t nmemb, size_t size,
|
||||||
int (*compar) (const void *, const void *))
|
int (*compar) (const void *, const void *))
|
||||||
{
|
{
|
||||||
size_t gap = nmemb;
|
size_t gap = nmemb;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
char *p1, *p2;
|
char *p1, *p2;
|
||||||
int swapped;
|
int swapped;
|
||||||
|
|
||||||
if (!nmemb)
|
if (!nmemb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
gap = newgap(gap);
|
gap = newgap(gap);
|
||||||
swapped = 0;
|
swapped = 0;
|
||||||
|
|
||||||
for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) {
|
for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) {
|
||||||
j = i + gap;
|
j = i + gap;
|
||||||
if (compar(p1, p2 = (char *)base + j * size) > 0) {
|
if (compar(p1, p2 = (char *)base + j * size) > 0) {
|
||||||
memswap(p1, p2, size);
|
memswap(p1, p2, size);
|
||||||
swapped = 1;
|
swapped = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (gap > 1 || swapped);
|
} while (gap > 1 || swapped);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@ extern unsigned short __rand48_seed[3];
|
||||||
|
|
||||||
unsigned short *seed48(unsigned short int xsubi[3])
|
unsigned short *seed48(unsigned short int xsubi[3])
|
||||||
{
|
{
|
||||||
static unsigned short oldseed[3];
|
static unsigned short oldseed[3];
|
||||||
memcpy(oldseed, __rand48_seed, sizeof __rand48_seed);
|
memcpy(oldseed, __rand48_seed, sizeof __rand48_seed);
|
||||||
memcpy(__rand48_seed, xsubi, sizeof __rand48_seed);
|
memcpy(__rand48_seed, xsubi, sizeof __rand48_seed);
|
||||||
|
|
||||||
return oldseed;
|
return oldseed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
int snprintf(char *buffer, size_t n, const char *format, ...)
|
int snprintf(char *buffer, size_t n, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsnprintf(buffer, n, format, ap);
|
rv = vsnprintf(buffer, n, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
|
|
||||||
int sprintf(char *buffer, const char *format, ...)
|
int sprintf(char *buffer, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsnprintf(buffer, (~(size_t) 0)>>1, format, ap);
|
rv = vsnprintf(buffer, (~(size_t) 0)>>1, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,17 +14,17 @@ extern unsigned short __rand48_seed[3];
|
||||||
|
|
||||||
void srand48(long seedval)
|
void srand48(long seedval)
|
||||||
{
|
{
|
||||||
__rand48_seed[0] = 0x330e;
|
__rand48_seed[0] = 0x330e;
|
||||||
__rand48_seed[1] = (unsigned short)seedval;
|
__rand48_seed[1] = (unsigned short)seedval;
|
||||||
__rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16);
|
__rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void srand(unsigned int __s)
|
void srand(unsigned int __s)
|
||||||
{
|
{
|
||||||
srand48(__s);
|
srand48(__s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void srandom(unsigned int __s)
|
void srandom(unsigned int __s)
|
||||||
{
|
{
|
||||||
srand48(__s);
|
srand48(__s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
|
|
||||||
int sscanf(const char *str, const char *format, ...)
|
int sscanf(const char *str, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
rv = vsscanf(str, format, ap);
|
rv = vsscanf(str, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
void *malloc(size_t size)
|
void *malloc(size_t size)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(void *ptr)
|
void free(void *ptr)
|
||||||
|
@ -19,10 +19,10 @@ void free(void *ptr)
|
||||||
|
|
||||||
void *calloc(size_t nmemb, size_t size)
|
void *calloc(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *realloc(void *ptr, size_t size)
|
void *realloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@
|
||||||
|
|
||||||
int strcasecmp(const char *s1, const char *s2)
|
int strcasecmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
const unsigned char *c1 = (const unsigned char *)s1;
|
const unsigned char *c1 = (const unsigned char *)s1;
|
||||||
const unsigned char *c2 = (const unsigned char *)s2;
|
const unsigned char *c2 = (const unsigned char *)s2;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
/* toupper() expects an unsigned char (implicitly cast to int)
|
/* toupper() expects an unsigned char (implicitly cast to int)
|
||||||
as input, and returns an int, which is exactly what we want. */
|
as input, and returns an int, which is exactly what we want. */
|
||||||
d = toupper(ch = *c1++) - toupper(*c2++);
|
d = toupper(ch = *c1++) - toupper(*c2++);
|
||||||
if (d || !ch)
|
if (d || !ch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
char *strcat(char *dst, const char *src)
|
char *strcat(char *dst, const char *src)
|
||||||
{
|
{
|
||||||
strcpy(strchr(dst, '\0'), src);
|
strcpy(strchr(dst, '\0'), src);
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
__WEAK__
|
__WEAK__
|
||||||
char *strchr(const char *s, int c)
|
char *strchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
while (*s != (char)c) {
|
while (*s != (char)c) {
|
||||||
if (!*s)
|
if (!*s)
|
||||||
return NULL;
|
return NULL;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *)s;
|
return (char *)s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@
|
||||||
|
|
||||||
int strcmp(const char *s1, const char *s2)
|
int strcmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
const unsigned char *c1 = (const unsigned char *)s1;
|
const unsigned char *c1 = (const unsigned char *)s1;
|
||||||
const unsigned char *c2 = (const unsigned char *)s2;
|
const unsigned char *c2 = (const unsigned char *)s2;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
d = (int)(ch = *c1++) - (int)*c2++;
|
d = (int)(ch = *c1++) - (int)*c2++;
|
||||||
if (d || !ch)
|
if (d || !ch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
|
|
||||||
char *strcpy(char *dst, const char *src)
|
char *strcpy(char *dst, const char *src)
|
||||||
{
|
{
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
*q++ = ch = *p++;
|
*q++ = ch = *p++;
|
||||||
} while (ch);
|
} while (ch);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
|
|
||||||
size_t strcspn(const char *s, const char *reject)
|
size_t strcspn(const char *s, const char *reject)
|
||||||
{
|
{
|
||||||
return __strxspn(s, reject, 1);
|
return __strxspn(s, reject, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,25 +10,25 @@
|
||||||
|
|
||||||
size_t strlcat(char *dst, const char *src, size_t size)
|
size_t strlcat(char *dst, const char *src, size_t size)
|
||||||
{
|
{
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while (bytes < size && *q) {
|
while (bytes < size && *q) {
|
||||||
q++;
|
q++;
|
||||||
bytes++;
|
bytes++;
|
||||||
}
|
}
|
||||||
if (bytes == size)
|
if (bytes == size)
|
||||||
return (bytes + strlen(src));
|
return (bytes + strlen(src));
|
||||||
|
|
||||||
while ((ch = *p++)) {
|
while ((ch = *p++)) {
|
||||||
if (bytes + 1 < size)
|
if (bytes + 1 < size)
|
||||||
*q++ = ch;
|
*q++ = ch;
|
||||||
|
|
||||||
bytes++;
|
bytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,21 +10,21 @@
|
||||||
|
|
||||||
size_t strlcpy(char *dst, const char *src, size_t size)
|
size_t strlcpy(char *dst, const char *src, size_t size)
|
||||||
{
|
{
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while ((ch = *p++)) {
|
while ((ch = *p++)) {
|
||||||
if (bytes + 1 < size)
|
if (bytes + 1 < size)
|
||||||
*q++ = ch;
|
*q++ = ch;
|
||||||
|
|
||||||
bytes++;
|
bytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If size == 0 there is no space for a final null... */
|
/* If size == 0 there is no space for a final null... */
|
||||||
if (size)
|
if (size)
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
size_t strlen(const char *s)
|
size_t strlen(const char *s)
|
||||||
{
|
{
|
||||||
const char *ss = s;
|
const char *ss = s;
|
||||||
while (*ss)
|
while (*ss)
|
||||||
ss++;
|
ss++;
|
||||||
return ss - s;
|
return ss - s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@
|
||||||
|
|
||||||
int strncasecmp(const char *s1, const char *s2, size_t n)
|
int strncasecmp(const char *s1, const char *s2, size_t n)
|
||||||
{
|
{
|
||||||
const unsigned char *c1 = (const unsigned char *)s1;
|
const unsigned char *c1 = (const unsigned char *)s1;
|
||||||
const unsigned char *c2 = (const unsigned char *)s2;
|
const unsigned char *c2 = (const unsigned char *)s2;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
/* toupper() expects an unsigned char (implicitly cast to int)
|
/* toupper() expects an unsigned char (implicitly cast to int)
|
||||||
as input, and returns an int, which is exactly what we want. */
|
as input, and returns an int, which is exactly what we want. */
|
||||||
d = toupper(ch = *c1++) - toupper(*c2++);
|
d = toupper(ch = *c1++) - toupper(*c2++);
|
||||||
if (d || !ch)
|
if (d || !ch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@
|
||||||
|
|
||||||
char *strncat(char *dst, const char *src, size_t n)
|
char *strncat(char *dst, const char *src, size_t n)
|
||||||
{
|
{
|
||||||
char *q = strchr(dst, '\0');
|
char *q = strchr(dst, '\0');
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
*q++ = ch = *p++;
|
*q++ = ch = *p++;
|
||||||
if (!ch)
|
if (!ch)
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@
|
||||||
|
|
||||||
int strncmp(const char *s1, const char *s2, size_t n)
|
int strncmp(const char *s1, const char *s2, size_t n)
|
||||||
{
|
{
|
||||||
const unsigned char *c1 = (const unsigned char *)s1;
|
const unsigned char *c1 = (const unsigned char *)s1;
|
||||||
const unsigned char *c2 = (const unsigned char *)s2;
|
const unsigned char *c2 = (const unsigned char *)s2;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
int d = 0;
|
int d = 0;
|
||||||
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
d = (int)(ch = *c1++) - (int)*c2++;
|
d = (int)(ch = *c1++) - (int)*c2++;
|
||||||
if (d || !ch)
|
if (d || !ch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,19 +10,19 @@
|
||||||
|
|
||||||
char *strncpy(char *dst, const char *src, size_t n)
|
char *strncpy(char *dst, const char *src, size_t n)
|
||||||
{
|
{
|
||||||
char *q = dst;
|
char *q = dst;
|
||||||
const char *p = src;
|
const char *p = src;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
n--;
|
n--;
|
||||||
*q++ = ch = *p++;
|
*q++ = ch = *p++;
|
||||||
if (!ch)
|
if (!ch)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The specs say strncpy() fills the entire buffer with NUL. Sigh. */
|
/* The specs say strncpy() fills the entire buffer with NUL. Sigh. */
|
||||||
memset(q, 0, n);
|
memset(q, 0, n);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
|
|
||||||
size_t strnlen(const char *s, size_t maxlen)
|
size_t strnlen(const char *s, size_t maxlen)
|
||||||
{
|
{
|
||||||
const char *ss = s;
|
const char *ss = s;
|
||||||
|
|
||||||
/* Important: the maxlen test must precede the reference through ss;
|
/* Important: the maxlen test must precede the reference through ss;
|
||||||
since the byte beyond the maximum may segfault */
|
since the byte beyond the maximum may segfault */
|
||||||
while ((maxlen > 0) && *ss) {
|
while ((maxlen > 0) && *ss) {
|
||||||
ss++;
|
ss++;
|
||||||
maxlen--;
|
maxlen--;
|
||||||
}
|
}
|
||||||
return ss - s;
|
return ss - s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@
|
||||||
|
|
||||||
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
|
intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
|
||||||
{
|
{
|
||||||
return (intmax_t) strntoumax(nptr, endptr, base, n);
|
return (intmax_t) strntoumax(nptr, endptr, base, n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,67 +15,67 @@
|
||||||
|
|
||||||
static __inline int digitval(int ch)
|
static __inline int digitval(int ch)
|
||||||
{
|
{
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
return ch - '0';
|
return ch - '0';
|
||||||
} else if (ch >= 'A' && ch <= 'Z') {
|
} else if (ch >= 'A' && ch <= 'Z') {
|
||||||
return ch - 'A' + 10;
|
return ch - 'A' + 10;
|
||||||
} else if (ch >= 'a' && ch <= 'z') {
|
} else if (ch >= 'a' && ch <= 'z') {
|
||||||
return ch - 'a' + 10;
|
return ch - 'a' + 10;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
|
||||||
{
|
{
|
||||||
int minus = 0;
|
int minus = 0;
|
||||||
uintmax_t v = 0;
|
uintmax_t v = 0;
|
||||||
int d;
|
int d;
|
||||||
|
|
||||||
while (n && isspace((unsigned char)*nptr)) {
|
while (n && isspace((unsigned char)*nptr)) {
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Single optional + or - */
|
/* Single optional + or - */
|
||||||
if (n) {
|
if (n) {
|
||||||
char c = *nptr;
|
char c = *nptr;
|
||||||
if (c == '-' || c == '+') {
|
if (c == '-' || c == '+') {
|
||||||
minus = (c == '-');
|
minus = (c == '-');
|
||||||
nptr++;
|
nptr++;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
base = 16;
|
base = 16;
|
||||||
} else if (n >= 1 && nptr[0] == '0') {
|
} else if (n >= 1 && nptr[0] == '0') {
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
base = 8;
|
base = 8;
|
||||||
} else {
|
} else {
|
||||||
base = 10;
|
base = 10;
|
||||||
}
|
}
|
||||||
} else if (base == 16) {
|
} else if (base == 16) {
|
||||||
if (n >= 2 && nptr[0] == '0' &&
|
if (n >= 2 && nptr[0] == '0' &&
|
||||||
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
(nptr[1] == 'x' || nptr[1] == 'X')) {
|
||||||
n -= 2;
|
n -= 2;
|
||||||
nptr += 2;
|
nptr += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
while (n && (d = digitval(*nptr)) >= 0 && d < base) {
|
||||||
v = v * base + d;
|
v = v * base + d;
|
||||||
n--;
|
n--;
|
||||||
nptr++;
|
nptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endptr)
|
if (endptr)
|
||||||
*endptr = (char *)nptr;
|
*endptr = (char *)nptr;
|
||||||
|
|
||||||
return minus ? -v : v;
|
return minus ? -v : v;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
char *strpbrk(const char *s, const char *accept)
|
char *strpbrk(const char *s, const char *accept)
|
||||||
{
|
{
|
||||||
const char *ss = s + __strxspn(s, accept, 1);
|
const char *ss = s + __strxspn(s, accept, 1);
|
||||||
|
|
||||||
return *ss ? (char *)ss : NULL;
|
return *ss ? (char *)ss : NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
|
|
||||||
char *strrchr(const char *s, int c)
|
char *strrchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
const char *found = NULL;
|
const char *found = NULL;
|
||||||
|
|
||||||
while (*s) {
|
while (*s) {
|
||||||
if (*s == (char)c)
|
if (*s == (char)c)
|
||||||
found = s;
|
found = s;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char *)found;
|
return (char *)found;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,16 @@
|
||||||
|
|
||||||
char *strsep(char **stringp, const char *delim)
|
char *strsep(char **stringp, const char *delim)
|
||||||
{
|
{
|
||||||
char *s = *stringp;
|
char *s = *stringp;
|
||||||
char *e;
|
char *e;
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
e = strpbrk(s, delim);
|
e = strpbrk(s, delim);
|
||||||
if (e)
|
if (e)
|
||||||
*e++ = '\0';
|
*e++ = '\0';
|
||||||
|
|
||||||
*stringp = e;
|
*stringp = e;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
|
|
||||||
size_t strspn(const char *s, const char *accept)
|
size_t strspn(const char *s, const char *accept)
|
||||||
{
|
{
|
||||||
return __strxspn(s, accept, 0);
|
return __strxspn(s, accept, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,6 @@
|
||||||
|
|
||||||
char *strstr(const char *haystack, const char *needle)
|
char *strstr(const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
return (char *)memmem(haystack, strlen(haystack), needle,
|
return (char *)memmem(haystack, strlen(haystack), needle,
|
||||||
strlen(needle));
|
strlen(needle));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
char *strtok(char *s, const char *delim)
|
char *strtok(char *s, const char *delim)
|
||||||
{
|
{
|
||||||
static char *holder;
|
static char *holder;
|
||||||
|
|
||||||
return strtok_r(s, delim, &holder);
|
return strtok_r(s, delim, &holder);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
char *strtok_r(char *s, const char *delim, char **holder)
|
char *strtok_r(char *s, const char *delim, char **holder)
|
||||||
{
|
{
|
||||||
if (s)
|
if (s)
|
||||||
*holder = s;
|
*holder = s;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
s = strsep(holder, delim);
|
s = strsep(holder, delim);
|
||||||
} while (s && !*s);
|
} while (s && !*s);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,5 @@
|
||||||
|
|
||||||
WEAK TYPE NAME(const char *nptr, char **endptr, int base)
|
WEAK TYPE NAME(const char *nptr, char **endptr, int base)
|
||||||
{
|
{
|
||||||
return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
|
return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,20 +14,20 @@
|
||||||
|
|
||||||
size_t __strxspn(const char *s, const char *map, int parity)
|
size_t __strxspn(const char *s, const char *map, int parity)
|
||||||
{
|
{
|
||||||
char matchmap[UCHAR_MAX + 1];
|
char matchmap[UCHAR_MAX + 1];
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
||||||
/* Create bitmap */
|
/* Create bitmap */
|
||||||
memset(matchmap, 0, sizeof matchmap);
|
memset(matchmap, 0, sizeof matchmap);
|
||||||
while (*map)
|
while (*map)
|
||||||
matchmap[(unsigned char)*map++] = 1;
|
matchmap[(unsigned char)*map++] = 1;
|
||||||
|
|
||||||
/* Make sure the null character never matches */
|
/* Make sure the null character never matches */
|
||||||
matchmap[0] = parity;
|
matchmap[0] = parity;
|
||||||
|
|
||||||
/* Calculate span length */
|
/* Calculate span length */
|
||||||
while (matchmap[(unsigned char)*s++] ^ parity)
|
while (matchmap[(unsigned char)*s++] ^ parity)
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,484 +17,484 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
enum flag {
|
enum flag {
|
||||||
FL_ZERO = 0x01, /* Zero modifier */
|
FL_ZERO = 0x01, /* Zero modifier */
|
||||||
FL_MINUS = 0x02, /* Minus modifier */
|
FL_MINUS = 0x02, /* Minus modifier */
|
||||||
FL_PLUS = 0x04, /* Plus modifier */
|
FL_PLUS = 0x04, /* Plus modifier */
|
||||||
FL_TICK = 0x08, /* ' modifier */
|
FL_TICK = 0x08, /* ' modifier */
|
||||||
FL_SPACE = 0x10, /* Space modifier */
|
FL_SPACE = 0x10, /* Space modifier */
|
||||||
FL_HASH = 0x20, /* # modifier */
|
FL_HASH = 0x20, /* # modifier */
|
||||||
FL_SIGNED = 0x40, /* Number is signed */
|
FL_SIGNED = 0x40, /* Number is signed */
|
||||||
FL_UPPER = 0x80 /* Upper case digits */
|
FL_UPPER = 0x80 /* Upper case digits */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* These may have to be adjusted on certain implementations */
|
/* These may have to be adjusted on certain implementations */
|
||||||
enum ranks {
|
enum ranks {
|
||||||
rank_char = -2,
|
rank_char = -2,
|
||||||
rank_short = -1,
|
rank_short = -1,
|
||||||
rank_int = 0,
|
rank_int = 0,
|
||||||
rank_long = 1,
|
rank_long = 1,
|
||||||
rank_longlong = 2
|
rank_longlong = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MIN_RANK rank_char
|
#define MIN_RANK rank_char
|
||||||
#define MAX_RANK rank_longlong
|
#define MAX_RANK rank_longlong
|
||||||
|
|
||||||
#define INTMAX_RANK rank_longlong
|
#define INTMAX_RANK rank_longlong
|
||||||
#define SIZE_T_RANK rank_long
|
#define SIZE_T_RANK rank_long
|
||||||
#define PTRDIFF_T_RANK rank_long
|
#define PTRDIFF_T_RANK rank_long
|
||||||
|
|
||||||
#define EMIT(x) { if (o < n) { *q++ = (x); } o++; }
|
#define EMIT(x) { if (o < n) { *q++ = (x); } o++; }
|
||||||
static size_t
|
static size_t
|
||||||
format_int(char *q, size_t n, uintmax_t val, unsigned int flags,
|
format_int(char *q, size_t n, uintmax_t val, unsigned int flags,
|
||||||
int base, int width, int prec)
|
int base, int width, int prec)
|
||||||
{
|
{
|
||||||
char *qq;
|
char *qq;
|
||||||
size_t o = 0, oo;
|
size_t o = 0, oo;
|
||||||
static const char lcdigits[] = "0123456789abcdef";
|
static const char lcdigits[] = "0123456789abcdef";
|
||||||
static const char ucdigits[] = "0123456789ABCDEF";
|
static const char ucdigits[] = "0123456789ABCDEF";
|
||||||
const char *digits;
|
const char *digits;
|
||||||
uintmax_t tmpval;
|
uintmax_t tmpval;
|
||||||
int minus = 0;
|
int minus = 0;
|
||||||
int ndigits = 0, nchars;
|
int ndigits = 0, nchars;
|
||||||
int tickskip, b4tick;
|
int tickskip, b4tick;
|
||||||
|
|
||||||
/* Select type of digits */
|
/* Select type of digits */
|
||||||
digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
|
digits = (flags & FL_UPPER) ? ucdigits : lcdigits;
|
||||||
|
|
||||||
/* If signed, separate out the minus */
|
/* If signed, separate out the minus */
|
||||||
if (flags & FL_SIGNED && (intmax_t) val < 0) {
|
if (flags & FL_SIGNED && (intmax_t) val < 0) {
|
||||||
minus = 1;
|
minus = 1;
|
||||||
val = (uintmax_t) (-(intmax_t) val);
|
val = (uintmax_t) (-(intmax_t) val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count the number of digits needed. This returns zero for 0. */
|
/* Count the number of digits needed. This returns zero for 0. */
|
||||||
tmpval = val;
|
tmpval = val;
|
||||||
while (tmpval) {
|
while (tmpval) {
|
||||||
tmpval /= base;
|
tmpval /= base;
|
||||||
ndigits++;
|
ndigits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust ndigits for size of output */
|
/* Adjust ndigits for size of output */
|
||||||
|
|
||||||
if (flags & FL_HASH && base == 8) {
|
if (flags & FL_HASH && base == 8) {
|
||||||
if (prec < ndigits + 1)
|
if (prec < ndigits + 1)
|
||||||
prec = ndigits + 1;
|
prec = ndigits + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ndigits < prec) {
|
if (ndigits < prec) {
|
||||||
ndigits = prec; /* Mandatory number padding */
|
ndigits = prec; /* Mandatory number padding */
|
||||||
} else if (val == 0) {
|
} else if (val == 0) {
|
||||||
ndigits = 1; /* Zero still requires space */
|
ndigits = 1; /* Zero still requires space */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For ', figure out what the skip should be */
|
/* For ', figure out what the skip should be */
|
||||||
if (flags & FL_TICK) {
|
if (flags & FL_TICK) {
|
||||||
tickskip = (base == 16) ? 4 : 3;
|
tickskip = (base == 16) ? 4 : 3;
|
||||||
} else {
|
} else {
|
||||||
tickskip = ndigits; /* No tick marks */
|
tickskip = ndigits; /* No tick marks */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tick marks aren't digits, but generated by the number converter */
|
/* Tick marks aren't digits, but generated by the number converter */
|
||||||
ndigits += (ndigits - 1) / tickskip;
|
ndigits += (ndigits - 1) / tickskip;
|
||||||
|
|
||||||
/* Now compute the number of nondigits */
|
/* Now compute the number of nondigits */
|
||||||
nchars = ndigits;
|
nchars = ndigits;
|
||||||
|
|
||||||
if (minus || (flags & (FL_PLUS | FL_SPACE)))
|
if (minus || (flags & (FL_PLUS | FL_SPACE)))
|
||||||
nchars++; /* Need space for sign */
|
nchars++; /* Need space for sign */
|
||||||
if ((flags & FL_HASH) && base == 16) {
|
if ((flags & FL_HASH) && base == 16) {
|
||||||
nchars += 2; /* Add 0x for hex */
|
nchars += 2; /* Add 0x for hex */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit early space padding */
|
/* Emit early space padding */
|
||||||
if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
|
if (!(flags & (FL_MINUS | FL_ZERO)) && width > nchars) {
|
||||||
while (width > nchars) {
|
while (width > nchars) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit nondigits */
|
/* Emit nondigits */
|
||||||
if (minus) {
|
if (minus) {
|
||||||
EMIT('-');
|
EMIT('-');
|
||||||
} else if (flags & FL_PLUS) {
|
} else if (flags & FL_PLUS) {
|
||||||
EMIT('+');
|
EMIT('+');
|
||||||
} else if (flags & FL_SPACE) {
|
} else if (flags & FL_SPACE) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & FL_HASH) && base == 16) {
|
if ((flags & FL_HASH) && base == 16) {
|
||||||
EMIT('0');
|
EMIT('0');
|
||||||
EMIT((flags & FL_UPPER) ? 'X' : 'x');
|
EMIT((flags & FL_UPPER) ? 'X' : 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit zero padding */
|
/* Emit zero padding */
|
||||||
if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
|
if ((flags & (FL_MINUS | FL_ZERO)) == FL_ZERO && width > ndigits) {
|
||||||
while (width > nchars) {
|
while (width > nchars) {
|
||||||
EMIT('0');
|
EMIT('0');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the number. This is done from right to left. */
|
/* Generate the number. This is done from right to left. */
|
||||||
q += ndigits; /* Advance the pointer to end of number */
|
q += ndigits; /* Advance the pointer to end of number */
|
||||||
o += ndigits;
|
o += ndigits;
|
||||||
qq = q;
|
qq = q;
|
||||||
oo = o; /* Temporary values */
|
oo = o; /* Temporary values */
|
||||||
|
|
||||||
b4tick = tickskip;
|
b4tick = tickskip;
|
||||||
while (ndigits > 0) {
|
while (ndigits > 0) {
|
||||||
if (!b4tick--) {
|
if (!b4tick--) {
|
||||||
qq--;
|
qq--;
|
||||||
oo--;
|
oo--;
|
||||||
ndigits--;
|
ndigits--;
|
||||||
if (oo < n)
|
if (oo < n)
|
||||||
*qq = '_';
|
*qq = '_';
|
||||||
b4tick = tickskip - 1;
|
b4tick = tickskip - 1;
|
||||||
}
|
}
|
||||||
qq--;
|
qq--;
|
||||||
oo--;
|
oo--;
|
||||||
ndigits--;
|
ndigits--;
|
||||||
if (oo < n)
|
if (oo < n)
|
||||||
*qq = digits[val % base];
|
*qq = digits[val % base];
|
||||||
val /= base;
|
val /= base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Emit late space padding */
|
/* Emit late space padding */
|
||||||
while ((flags & FL_MINUS) && width > nchars) {
|
while ((flags & FL_MINUS) && width > nchars) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
int vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
const char *p = format;
|
const char *p = format;
|
||||||
char ch;
|
char ch;
|
||||||
char *q = buffer;
|
char *q = buffer;
|
||||||
size_t o = 0; /* Number of characters output */
|
size_t o = 0; /* Number of characters output */
|
||||||
uintmax_t val = 0;
|
uintmax_t val = 0;
|
||||||
int rank = rank_int; /* Default rank */
|
int rank = rank_int; /* Default rank */
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int prec = -1;
|
int prec = -1;
|
||||||
int base;
|
int base;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
enum {
|
enum {
|
||||||
st_normal, /* Ground state */
|
st_normal, /* Ground state */
|
||||||
st_flags, /* Special flags */
|
st_flags, /* Special flags */
|
||||||
st_width, /* Field width */
|
st_width, /* Field width */
|
||||||
st_prec, /* Field precision */
|
st_prec, /* Field precision */
|
||||||
st_modifiers /* Length or conversion modifiers */
|
st_modifiers /* Length or conversion modifiers */
|
||||||
} state = st_normal;
|
} state = st_normal;
|
||||||
const char *sarg; /* %s string argument */
|
const char *sarg; /* %s string argument */
|
||||||
char carg; /* %c char argument */
|
char carg; /* %c char argument */
|
||||||
int slen; /* String length */
|
int slen; /* String length */
|
||||||
|
|
||||||
while ((ch = *p++)) {
|
while ((ch = *p++)) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case st_normal:
|
case st_normal:
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
state = st_flags;
|
state = st_flags;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
rank = rank_int;
|
rank = rank_int;
|
||||||
width = 0;
|
width = 0;
|
||||||
prec = -1;
|
prec = -1;
|
||||||
} else {
|
} else {
|
||||||
EMIT(ch);
|
EMIT(ch);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_flags:
|
case st_flags:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '-':
|
case '-':
|
||||||
flags |= FL_MINUS;
|
flags |= FL_MINUS;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
flags |= FL_PLUS;
|
flags |= FL_PLUS;
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
flags |= FL_TICK;
|
flags |= FL_TICK;
|
||||||
break;
|
break;
|
||||||
case ' ':
|
case ' ':
|
||||||
flags |= FL_SPACE;
|
flags |= FL_SPACE;
|
||||||
break;
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
flags |= FL_HASH;
|
flags |= FL_HASH;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
flags |= FL_ZERO;
|
flags |= FL_ZERO;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state = st_width;
|
state = st_width;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_width:
|
case st_width:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
width = width * 10 + (ch - '0');
|
width = width * 10 + (ch - '0');
|
||||||
} else if (ch == '*') {
|
} else if (ch == '*') {
|
||||||
width = va_arg(ap, int);
|
width = va_arg(ap, int);
|
||||||
if (width < 0) {
|
if (width < 0) {
|
||||||
width = -width;
|
width = -width;
|
||||||
flags |= FL_MINUS;
|
flags |= FL_MINUS;
|
||||||
}
|
}
|
||||||
} else if (ch == '.') {
|
} else if (ch == '.') {
|
||||||
prec = 0; /* Precision given */
|
prec = 0; /* Precision given */
|
||||||
state = st_prec;
|
state = st_prec;
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_prec:
|
case st_prec:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
prec = prec * 10 + (ch - '0');
|
prec = prec * 10 + (ch - '0');
|
||||||
} else if (ch == '*') {
|
} else if (ch == '*') {
|
||||||
prec = va_arg(ap, int);
|
prec = va_arg(ap, int);
|
||||||
if (prec < 0)
|
if (prec < 0)
|
||||||
prec = -1;
|
prec = -1;
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_modifiers:
|
case st_modifiers:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* Length modifiers - nonterminal sequences */
|
/* Length modifiers - nonterminal sequences */
|
||||||
case 'h':
|
case 'h':
|
||||||
rank--; /* Shorter rank */
|
rank--; /* Shorter rank */
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
rank++; /* Longer rank */
|
rank++; /* Longer rank */
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
rank = INTMAX_RANK;
|
rank = INTMAX_RANK;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
rank = SIZE_T_RANK;
|
rank = SIZE_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
rank = PTRDIFF_T_RANK;
|
rank = PTRDIFF_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'q':
|
case 'q':
|
||||||
rank += 2;
|
rank += 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Output modifiers - terminal sequences */
|
/* Output modifiers - terminal sequences */
|
||||||
|
|
||||||
/* Next state will be normal */
|
/* Next state will be normal */
|
||||||
state = st_normal;
|
state = st_normal;
|
||||||
|
|
||||||
/* Canonicalize rank */
|
/* Canonicalize rank */
|
||||||
if (rank < MIN_RANK)
|
if (rank < MIN_RANK)
|
||||||
rank = MIN_RANK;
|
rank = MIN_RANK;
|
||||||
else if (rank > MAX_RANK)
|
else if (rank > MAX_RANK)
|
||||||
rank = MAX_RANK;
|
rank = MAX_RANK;
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'P': /* Upper case pointer */
|
case 'P': /* Upper case pointer */
|
||||||
flags |= FL_UPPER;
|
flags |= FL_UPPER;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'p': /* Pointer */
|
case 'p': /* Pointer */
|
||||||
base = 16;
|
base = 16;
|
||||||
prec = (CHAR_BIT*sizeof(void *)+3)/4;
|
prec = (CHAR_BIT*sizeof(void *)+3)/4;
|
||||||
flags |= FL_HASH;
|
flags |= FL_HASH;
|
||||||
val = (uintmax_t)(uintptr_t)
|
val = (uintmax_t)(uintptr_t)
|
||||||
va_arg(ap, void *);
|
va_arg(ap, void *);
|
||||||
goto is_integer;
|
goto is_integer;
|
||||||
|
|
||||||
case 'd': /* Signed decimal output */
|
case 'd': /* Signed decimal output */
|
||||||
case 'i':
|
case 'i':
|
||||||
base = 10;
|
base = 10;
|
||||||
flags |= FL_SIGNED;
|
flags |= FL_SIGNED;
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
/* Yes, all these casts are
|
/* Yes, all these casts are
|
||||||
needed... */
|
needed... */
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
(signed char)
|
(signed char)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
(signed short)
|
(signed short)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap, signed int);
|
va_arg(ap, signed int);
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap, signed long);
|
va_arg(ap, signed long);
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
val = (uintmax_t)(intmax_t)
|
val = (uintmax_t)(intmax_t)
|
||||||
va_arg(ap,
|
va_arg(ap,
|
||||||
signed long long);
|
signed long long);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
goto is_integer;
|
goto is_integer;
|
||||||
case 'o': /* Octal */
|
case 'o': /* Octal */
|
||||||
base = 8;
|
base = 8;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
case 'u': /* Unsigned decimal */
|
case 'u': /* Unsigned decimal */
|
||||||
base = 10;
|
base = 10;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
case 'X': /* Upper case hexadecimal */
|
case 'X': /* Upper case hexadecimal */
|
||||||
flags |= FL_UPPER;
|
flags |= FL_UPPER;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case 'x': /* Hexadecimal */
|
case 'x': /* Hexadecimal */
|
||||||
base = 16;
|
base = 16;
|
||||||
goto is_unsigned;
|
goto is_unsigned;
|
||||||
|
|
||||||
is_unsigned:
|
is_unsigned:
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
(unsigned char)
|
(unsigned char)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
(unsigned short)
|
(unsigned short)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
int);
|
int);
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
long);
|
long);
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
val = (uintmax_t)
|
val = (uintmax_t)
|
||||||
va_arg(ap, unsigned
|
va_arg(ap, unsigned
|
||||||
long long);
|
long long);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
is_integer:
|
is_integer:
|
||||||
sz = format_int(q, (o < n) ? n - o : 0,
|
sz = format_int(q, (o < n) ? n - o : 0,
|
||||||
val, flags, base,
|
val, flags, base,
|
||||||
width, prec);
|
width, prec);
|
||||||
q += sz;
|
q += sz;
|
||||||
o += sz;
|
o += sz;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* Character */
|
case 'c': /* Character */
|
||||||
carg = (char)va_arg(ap, int);
|
carg = (char)va_arg(ap, int);
|
||||||
sarg = &carg;
|
sarg = &carg;
|
||||||
slen = 1;
|
slen = 1;
|
||||||
goto is_string;
|
goto is_string;
|
||||||
case 's': /* String */
|
case 's': /* String */
|
||||||
sarg = va_arg(ap, const char *);
|
sarg = va_arg(ap, const char *);
|
||||||
sarg = sarg ? sarg : "(null)";
|
sarg = sarg ? sarg : "(null)";
|
||||||
slen = strlen(sarg);
|
slen = strlen(sarg);
|
||||||
goto is_string;
|
goto is_string;
|
||||||
|
|
||||||
is_string:
|
is_string:
|
||||||
{
|
{
|
||||||
char sch;
|
char sch;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (prec != -1 && slen > prec)
|
if (prec != -1 && slen > prec)
|
||||||
slen = prec;
|
slen = prec;
|
||||||
|
|
||||||
if (width > slen
|
if (width > slen
|
||||||
&& !(flags & FL_MINUS)) {
|
&& !(flags & FL_MINUS)) {
|
||||||
char pad =
|
char pad =
|
||||||
(flags & FL_ZERO) ?
|
(flags & FL_ZERO) ?
|
||||||
'0' : ' ';
|
'0' : ' ';
|
||||||
while (width > slen) {
|
while (width > slen) {
|
||||||
EMIT(pad);
|
EMIT(pad);
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = slen; i; i--) {
|
for (i = slen; i; i--) {
|
||||||
sch = *sarg++;
|
sch = *sarg++;
|
||||||
EMIT(sch);
|
EMIT(sch);
|
||||||
}
|
}
|
||||||
if (width > slen
|
if (width > slen
|
||||||
&& (flags & FL_MINUS)) {
|
&& (flags & FL_MINUS)) {
|
||||||
while (width > slen) {
|
while (width > slen) {
|
||||||
EMIT(' ');
|
EMIT(' ');
|
||||||
width--;
|
width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
/* Output the number of
|
/* Output the number of
|
||||||
characters written */
|
characters written */
|
||||||
|
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed char *)
|
signed char *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed short *)
|
signed short *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed int *)
|
signed int *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed long *)
|
signed long *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
signed long long *)
|
signed long long *)
|
||||||
= o;
|
= o;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* Anything else, including % */
|
default: /* Anything else, including % */
|
||||||
EMIT(ch);
|
EMIT(ch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Null-terminate the string */
|
/* Null-terminate the string */
|
||||||
if (o < n)
|
if (o < n)
|
||||||
*q = '\0'; /* No overflow */
|
*q = '\0'; /* No overflow */
|
||||||
else if (n > 0)
|
else if (n > 0)
|
||||||
buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
|
buffer[n - 1] = '\0'; /* Overflow - terminate at end of buffer */
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,5 +11,5 @@
|
||||||
|
|
||||||
int vsprintf(char *buffer, const char *format, va_list ap)
|
int vsprintf(char *buffer, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
return vsnprintf(buffer, (~(size_t) 0)>>1, format, ap);
|
return vsnprintf(buffer, (~(size_t) 0)>>1, format, ap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,395 +24,395 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum flag {
|
enum flag {
|
||||||
FL_SPLAT = 0x01, /* Drop the value, do not assign */
|
FL_SPLAT = 0x01, /* Drop the value, do not assign */
|
||||||
FL_INV = 0x02, /* Character-set with inverse */
|
FL_INV = 0x02, /* Character-set with inverse */
|
||||||
FL_WIDTH = 0x04, /* Field width specified */
|
FL_WIDTH = 0x04, /* Field width specified */
|
||||||
FL_MINUS = 0x08, /* Negative number */
|
FL_MINUS = 0x08, /* Negative number */
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ranks {
|
enum ranks {
|
||||||
rank_char = -2,
|
rank_char = -2,
|
||||||
rank_short = -1,
|
rank_short = -1,
|
||||||
rank_int = 0,
|
rank_int = 0,
|
||||||
rank_long = 1,
|
rank_long = 1,
|
||||||
rank_longlong = 2,
|
rank_longlong = 2,
|
||||||
rank_ptr = INT_MAX /* Special value used for pointers */
|
rank_ptr = INT_MAX /* Special value used for pointers */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MIN_RANK rank_char
|
#define MIN_RANK rank_char
|
||||||
#define MAX_RANK rank_longlong
|
#define MAX_RANK rank_longlong
|
||||||
|
|
||||||
#define INTMAX_RANK rank_longlong
|
#define INTMAX_RANK rank_longlong
|
||||||
#define SIZE_T_RANK rank_long
|
#define SIZE_T_RANK rank_long
|
||||||
#define PTRDIFF_T_RANK rank_long
|
#define PTRDIFF_T_RANK rank_long
|
||||||
|
|
||||||
enum bail {
|
enum bail {
|
||||||
bail_none = 0, /* No error condition */
|
bail_none = 0, /* No error condition */
|
||||||
bail_eof, /* Hit EOF */
|
bail_eof, /* Hit EOF */
|
||||||
bail_err /* Conversion mismatch */
|
bail_err /* Conversion mismatch */
|
||||||
};
|
};
|
||||||
|
|
||||||
static __inline const char *skipspace(const char *p)
|
static __inline const char *skipspace(const char *p)
|
||||||
{
|
{
|
||||||
while (isspace((unsigned char)*p))
|
while (isspace((unsigned char)*p))
|
||||||
p++;
|
p++;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef set_bit
|
#undef set_bit
|
||||||
static __inline void set_bit(unsigned long *bitmap, unsigned int bit)
|
static __inline void set_bit(unsigned long *bitmap, unsigned int bit)
|
||||||
{
|
{
|
||||||
bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
|
bitmap[bit / LONG_BIT] |= 1UL << (bit % LONG_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef test_bit
|
#undef test_bit
|
||||||
static __inline int test_bit(unsigned long *bitmap, unsigned int bit)
|
static __inline int test_bit(unsigned long *bitmap, unsigned int bit)
|
||||||
{
|
{
|
||||||
return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
|
return (int)(bitmap[bit / LONG_BIT] >> (bit % LONG_BIT)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vsscanf(const char *buffer, const char *format, va_list ap)
|
int vsscanf(const char *buffer, const char *format, va_list ap)
|
||||||
{
|
{
|
||||||
const char *p = format;
|
const char *p = format;
|
||||||
char ch;
|
char ch;
|
||||||
unsigned char uc;
|
unsigned char uc;
|
||||||
const char *q = buffer;
|
const char *q = buffer;
|
||||||
const char *qq;
|
const char *qq;
|
||||||
uintmax_t val = 0;
|
uintmax_t val = 0;
|
||||||
int rank = rank_int; /* Default rank */
|
int rank = rank_int; /* Default rank */
|
||||||
unsigned int width = UINT_MAX;
|
unsigned int width = UINT_MAX;
|
||||||
int base;
|
int base;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
enum {
|
enum {
|
||||||
st_normal, /* Ground state */
|
st_normal, /* Ground state */
|
||||||
st_flags, /* Special flags */
|
st_flags, /* Special flags */
|
||||||
st_width, /* Field width */
|
st_width, /* Field width */
|
||||||
st_modifiers, /* Length or conversion modifiers */
|
st_modifiers, /* Length or conversion modifiers */
|
||||||
st_match_init, /* Initial state of %[ sequence */
|
st_match_init, /* Initial state of %[ sequence */
|
||||||
st_match, /* Main state of %[ sequence */
|
st_match, /* Main state of %[ sequence */
|
||||||
st_match_range, /* After - in a %[ sequence */
|
st_match_range, /* After - in a %[ sequence */
|
||||||
} state = st_normal;
|
} state = st_normal;
|
||||||
char *sarg = NULL; /* %s %c or %[ string argument */
|
char *sarg = NULL; /* %s %c or %[ string argument */
|
||||||
enum bail bail = bail_none;
|
enum bail bail = bail_none;
|
||||||
__UNUSED__ int sign;
|
__UNUSED__ int sign;
|
||||||
int converted = 0; /* Successful conversions */
|
int converted = 0; /* Successful conversions */
|
||||||
unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
|
unsigned long matchmap[((1 << CHAR_BIT) + (LONG_BIT - 1)) / LONG_BIT];
|
||||||
int matchinv = 0; /* Is match map inverted? */
|
int matchinv = 0; /* Is match map inverted? */
|
||||||
unsigned char range_start = 0;
|
unsigned char range_start = 0;
|
||||||
|
|
||||||
while ((ch = *p++) && !bail) {
|
while ((ch = *p++) && !bail) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case st_normal:
|
case st_normal:
|
||||||
if (ch == '%') {
|
if (ch == '%') {
|
||||||
state = st_flags;
|
state = st_flags;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
rank = rank_int;
|
rank = rank_int;
|
||||||
width = UINT_MAX;
|
width = UINT_MAX;
|
||||||
} else if (isspace((unsigned char)ch)) {
|
} else if (isspace((unsigned char)ch)) {
|
||||||
q = skipspace(q);
|
q = skipspace(q);
|
||||||
} else {
|
} else {
|
||||||
if (*q == ch)
|
if (*q == ch)
|
||||||
q++;
|
q++;
|
||||||
else
|
else
|
||||||
bail = bail_err; /* Match failure */
|
bail = bail_err; /* Match failure */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_flags:
|
case st_flags:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '*':
|
case '*':
|
||||||
flags |= FL_SPLAT;
|
flags |= FL_SPLAT;
|
||||||
break;
|
break;
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
case '3':
|
case '3':
|
||||||
case '4':
|
case '4':
|
||||||
case '5':
|
case '5':
|
||||||
case '6':
|
case '6':
|
||||||
case '7':
|
case '7':
|
||||||
case '8':
|
case '8':
|
||||||
case '9':
|
case '9':
|
||||||
width = (ch - '0');
|
width = (ch - '0');
|
||||||
state = st_width;
|
state = st_width;
|
||||||
flags |= FL_WIDTH;
|
flags |= FL_WIDTH;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_width:
|
case st_width:
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
width = width * 10 + (ch - '0');
|
width = width * 10 + (ch - '0');
|
||||||
} else {
|
} else {
|
||||||
state = st_modifiers;
|
state = st_modifiers;
|
||||||
p--; /* Process this character again */
|
p--; /* Process this character again */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_modifiers:
|
case st_modifiers:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
/* Length modifiers - nonterminal sequences */
|
/* Length modifiers - nonterminal sequences */
|
||||||
case 'h':
|
case 'h':
|
||||||
rank--; /* Shorter rank */
|
rank--; /* Shorter rank */
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
rank++; /* Longer rank */
|
rank++; /* Longer rank */
|
||||||
break;
|
break;
|
||||||
case 'j':
|
case 'j':
|
||||||
rank = INTMAX_RANK;
|
rank = INTMAX_RANK;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
rank = SIZE_T_RANK;
|
rank = SIZE_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
rank = PTRDIFF_T_RANK;
|
rank = PTRDIFF_T_RANK;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
case 'q':
|
case 'q':
|
||||||
rank = rank_longlong; /* long double/long long */
|
rank = rank_longlong; /* long double/long long */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Output modifiers - terminal sequences */
|
/* Output modifiers - terminal sequences */
|
||||||
/* Next state will be normal */
|
/* Next state will be normal */
|
||||||
state = st_normal;
|
state = st_normal;
|
||||||
|
|
||||||
/* Canonicalize rank */
|
/* Canonicalize rank */
|
||||||
if (rank < MIN_RANK)
|
if (rank < MIN_RANK)
|
||||||
rank = MIN_RANK;
|
rank = MIN_RANK;
|
||||||
else if (rank > MAX_RANK)
|
else if (rank > MAX_RANK)
|
||||||
rank = MAX_RANK;
|
rank = MAX_RANK;
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'P': /* Upper case pointer */
|
case 'P': /* Upper case pointer */
|
||||||
case 'p': /* Pointer */
|
case 'p': /* Pointer */
|
||||||
rank = rank_ptr;
|
rank = rank_ptr;
|
||||||
base = 0;
|
base = 0;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'i': /* Base-independent integer */
|
case 'i': /* Base-independent integer */
|
||||||
base = 0;
|
base = 0;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'd': /* Decimal integer */
|
case 'd': /* Decimal integer */
|
||||||
base = 10;
|
base = 10;
|
||||||
sign = 1;
|
sign = 1;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'o': /* Octal integer */
|
case 'o': /* Octal integer */
|
||||||
base = 8;
|
base = 8;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'u': /* Unsigned decimal integer */
|
case 'u': /* Unsigned decimal integer */
|
||||||
base = 10;
|
base = 10;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'x': /* Hexadecimal integer */
|
case 'x': /* Hexadecimal integer */
|
||||||
case 'X':
|
case 'X':
|
||||||
base = 16;
|
base = 16;
|
||||||
sign = 0;
|
sign = 0;
|
||||||
goto scan_int;
|
goto scan_int;
|
||||||
|
|
||||||
case 'n': /* # of characters consumed */
|
case 'n': /* # of characters consumed */
|
||||||
val = (q - buffer);
|
val = (q - buffer);
|
||||||
goto set_integer;
|
goto set_integer;
|
||||||
|
|
||||||
scan_int:
|
scan_int:
|
||||||
q = skipspace(q);
|
q = skipspace(q);
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
val =
|
val =
|
||||||
strntoumax(q, (char **)&qq, base,
|
strntoumax(q, (char **)&qq, base,
|
||||||
width);
|
width);
|
||||||
if (qq == q) {
|
if (qq == q) {
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
q = qq;
|
q = qq;
|
||||||
if (!(flags & FL_SPLAT))
|
if (!(flags & FL_SPLAT))
|
||||||
converted++;
|
converted++;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
|
||||||
set_integer:
|
set_integer:
|
||||||
if (!(flags & FL_SPLAT)) {
|
if (!(flags & FL_SPLAT)) {
|
||||||
switch (rank) {
|
switch (rank) {
|
||||||
case rank_char:
|
case rank_char:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned char *)
|
unsigned char *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_short:
|
case rank_short:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned short
|
unsigned short
|
||||||
*) = val;
|
*) = val;
|
||||||
break;
|
break;
|
||||||
case rank_int:
|
case rank_int:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned int *)
|
unsigned int *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_long:
|
case rank_long:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned long *)
|
unsigned long *)
|
||||||
= val;
|
= val;
|
||||||
break;
|
break;
|
||||||
case rank_longlong:
|
case rank_longlong:
|
||||||
*va_arg(ap,
|
*va_arg(ap,
|
||||||
unsigned long
|
unsigned long
|
||||||
long *) = val;
|
long *) = val;
|
||||||
break;
|
break;
|
||||||
case rank_ptr:
|
case rank_ptr:
|
||||||
*va_arg(ap, void **) =
|
*va_arg(ap, void **) =
|
||||||
(void *)
|
(void *)
|
||||||
(uintptr_t)val;
|
(uintptr_t)val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* Character */
|
case 'c': /* Character */
|
||||||
/* Default width == 1 */
|
/* Default width == 1 */
|
||||||
width = (flags & FL_WIDTH) ? width : 1;
|
width = (flags & FL_WIDTH) ? width : 1;
|
||||||
if (flags & FL_SPLAT) {
|
if (flags & FL_SPLAT) {
|
||||||
while (width--) {
|
while (width--) {
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sarg = va_arg(ap, char *);
|
sarg = va_arg(ap, char *);
|
||||||
while (width--) {
|
while (width--) {
|
||||||
if (!*q) {
|
if (!*q) {
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*sarg++ = *q++;
|
*sarg++ = *q++;
|
||||||
}
|
}
|
||||||
if (!bail)
|
if (!bail)
|
||||||
converted++;
|
converted++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's': /* String */
|
case 's': /* String */
|
||||||
uc = 1; /* Anything nonzero */
|
uc = 1; /* Anything nonzero */
|
||||||
if (flags & FL_SPLAT) {
|
if (flags & FL_SPLAT) {
|
||||||
while (width-- && (uc = *q) &&
|
while (width-- && (uc = *q) &&
|
||||||
!isspace(uc)) {
|
!isspace(uc)) {
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *sp;
|
char *sp;
|
||||||
sp = sarg = va_arg(ap, char *);
|
sp = sarg = va_arg(ap, char *);
|
||||||
while (width-- && (uc = *q) &&
|
while (width-- && (uc = *q) &&
|
||||||
!isspace(uc)) {
|
!isspace(uc)) {
|
||||||
*sp++ = uc;
|
*sp++ = uc;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
if (sarg != sp) {
|
if (sarg != sp) {
|
||||||
/* Terminate output */
|
/* Terminate output */
|
||||||
*sp = '\0';
|
*sp = '\0';
|
||||||
converted++;
|
converted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!uc)
|
if (!uc)
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': /* Character range */
|
case '[': /* Character range */
|
||||||
sarg = (flags & FL_SPLAT) ? NULL
|
sarg = (flags & FL_SPLAT) ? NULL
|
||||||
: va_arg(ap, char *);
|
: va_arg(ap, char *);
|
||||||
state = st_match_init;
|
state = st_match_init;
|
||||||
matchinv = 0;
|
matchinv = 0;
|
||||||
memset(matchmap, 0, sizeof matchmap);
|
memset(matchmap, 0, sizeof matchmap);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '%': /* %% sequence */
|
case '%': /* %% sequence */
|
||||||
if (*q == '%')
|
if (*q == '%')
|
||||||
q++;
|
q++;
|
||||||
else
|
else
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* Anything else */
|
default: /* Anything else */
|
||||||
/* Unknown sequence */
|
/* Unknown sequence */
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match_init: /* Initial state for %[ match */
|
case st_match_init: /* Initial state for %[ match */
|
||||||
if (ch == '^' && !(flags & FL_INV)) {
|
if (ch == '^' && !(flags & FL_INV)) {
|
||||||
matchinv = 1;
|
matchinv = 1;
|
||||||
} else {
|
} else {
|
||||||
set_bit(matchmap, (unsigned char)ch);
|
set_bit(matchmap, (unsigned char)ch);
|
||||||
state = st_match;
|
state = st_match;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match: /* Main state for %[ match */
|
case st_match: /* Main state for %[ match */
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
goto match_run;
|
goto match_run;
|
||||||
} else if (ch == '-') {
|
} else if (ch == '-') {
|
||||||
range_start = (unsigned char)ch;
|
range_start = (unsigned char)ch;
|
||||||
state = st_match_range;
|
state = st_match_range;
|
||||||
} else {
|
} else {
|
||||||
set_bit(matchmap, (unsigned char)ch);
|
set_bit(matchmap, (unsigned char)ch);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case st_match_range: /* %[ match after - */
|
case st_match_range: /* %[ match after - */
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
/* - was last character */
|
/* - was last character */
|
||||||
set_bit(matchmap, (unsigned char)'-');
|
set_bit(matchmap, (unsigned char)'-');
|
||||||
goto match_run;
|
goto match_run;
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i = range_start; i < (unsigned char)ch;
|
for (i = range_start; i < (unsigned char)ch;
|
||||||
i++)
|
i++)
|
||||||
set_bit(matchmap, i);
|
set_bit(matchmap, i);
|
||||||
state = st_match;
|
state = st_match;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
match_run: /* Match expression finished */
|
match_run: /* Match expression finished */
|
||||||
qq = q;
|
qq = q;
|
||||||
uc = 1; /* Anything nonzero */
|
uc = 1; /* Anything nonzero */
|
||||||
while (width && (uc = *q)
|
while (width && (uc = *q)
|
||||||
&& test_bit(matchmap, uc)^matchinv) {
|
&& test_bit(matchmap, uc)^matchinv) {
|
||||||
if (sarg)
|
if (sarg)
|
||||||
*sarg++ = uc;
|
*sarg++ = uc;
|
||||||
q++;
|
q++;
|
||||||
}
|
}
|
||||||
if (q != qq && sarg) {
|
if (q != qq && sarg) {
|
||||||
*sarg = '\0';
|
*sarg = '\0';
|
||||||
converted++;
|
converted++;
|
||||||
} else {
|
} else {
|
||||||
bail = bail_err;
|
bail = bail_err;
|
||||||
}
|
}
|
||||||
if (!uc)
|
if (!uc)
|
||||||
bail = bail_eof;
|
bail = bail_eof;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bail == bail_eof && !converted)
|
if (bail == bail_eof && !converted)
|
||||||
converted = -1; /* Return EOF (-1) */
|
converted = -1; /* Return EOF (-1) */
|
||||||
|
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
#include "mcu_sdk_version.h"
|
#include "mcu_sdk_version.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void * pvPortMalloc( size_t xWantedSize );
|
void * pvPortMalloc( size_t xWantedSize );
|
||||||
void* pvPortRealloc(void* ptr, size_t newsize);
|
void* pvPortRealloc(void* ptr, size_t newsize);
|
||||||
void* pvPortCalloc(size_t numElements, size_t sizeOfElement);
|
void* pvPortCalloc(size_t numElements, size_t sizeOfElement);
|
||||||
void vPortFree( void *pv );
|
void vPortFree( void *pv );
|
||||||
|
|
||||||
#define bflb_platform_malloc pvPortMalloc
|
#define bflb_platform_malloc pvPortMalloc
|
||||||
#define bflb_platform_free vPortFree
|
#define bflb_platform_free vPortFree
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
#define XZ_H
|
#define XZ_H
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
# include <linux/stddef.h>
|
# include <linux/stddef.h>
|
||||||
# include <linux/types.h>
|
# include <linux/types.h>
|
||||||
#else
|
#else
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
|
|
||||||
/* In Linux, this is used to make extern functions static when needed. */
|
/* In Linux, this is used to make extern functions static when needed. */
|
||||||
#ifndef XZ_EXTERN
|
#ifndef XZ_EXTERN
|
||||||
# define XZ_EXTERN extern
|
# define XZ_EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,9 +54,9 @@ extern "C" {
|
||||||
* be built with fewer features to minimize code size.
|
* be built with fewer features to minimize code size.
|
||||||
*/
|
*/
|
||||||
enum xz_mode {
|
enum xz_mode {
|
||||||
XZ_SINGLE,
|
XZ_SINGLE,
|
||||||
XZ_PREALLOC,
|
XZ_PREALLOC,
|
||||||
XZ_DYNALLOC
|
XZ_DYNALLOC
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,15 +110,15 @@ enum xz_mode {
|
||||||
* is used instead of XZ_BUF_ERROR.
|
* is used instead of XZ_BUF_ERROR.
|
||||||
*/
|
*/
|
||||||
enum xz_ret {
|
enum xz_ret {
|
||||||
XZ_OK,
|
XZ_OK,
|
||||||
XZ_STREAM_END,
|
XZ_STREAM_END,
|
||||||
XZ_UNSUPPORTED_CHECK,
|
XZ_UNSUPPORTED_CHECK,
|
||||||
XZ_MEM_ERROR,
|
XZ_MEM_ERROR,
|
||||||
XZ_MEMLIMIT_ERROR,
|
XZ_MEMLIMIT_ERROR,
|
||||||
XZ_FORMAT_ERROR,
|
XZ_FORMAT_ERROR,
|
||||||
XZ_OPTIONS_ERROR,
|
XZ_OPTIONS_ERROR,
|
||||||
XZ_DATA_ERROR,
|
XZ_DATA_ERROR,
|
||||||
XZ_BUF_ERROR
|
XZ_BUF_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -138,13 +138,13 @@ enum xz_ret {
|
||||||
* the variables in_pos and out_pos are modified by the XZ code.
|
* the variables in_pos and out_pos are modified by the XZ code.
|
||||||
*/
|
*/
|
||||||
struct xz_buf {
|
struct xz_buf {
|
||||||
const uint8_t *in;
|
const uint8_t *in;
|
||||||
size_t in_pos;
|
size_t in_pos;
|
||||||
size_t in_size;
|
size_t in_size;
|
||||||
|
|
||||||
uint8_t *out;
|
uint8_t *out;
|
||||||
size_t out_pos;
|
size_t out_pos;
|
||||||
size_t out_size;
|
size_t out_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,11 +244,11 @@ XZ_EXTERN void xz_dec_end(struct xz_dec *s);
|
||||||
* care about the functions below.
|
* care about the functions below.
|
||||||
*/
|
*/
|
||||||
#ifndef XZ_INTERNAL_CRC32
|
#ifndef XZ_INTERNAL_CRC32
|
||||||
# ifdef __KERNEL__
|
# ifdef __KERNEL__
|
||||||
# define XZ_INTERNAL_CRC32 0
|
# define XZ_INTERNAL_CRC32 0
|
||||||
# else
|
# else
|
||||||
# define XZ_INTERNAL_CRC32 1
|
# define XZ_INTERNAL_CRC32 1
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -256,15 +256,15 @@ XZ_EXTERN void xz_dec_end(struct xz_dec *s);
|
||||||
* implementation is needed too.
|
* implementation is needed too.
|
||||||
*/
|
*/
|
||||||
#ifndef XZ_USE_CRC64
|
#ifndef XZ_USE_CRC64
|
||||||
# undef XZ_INTERNAL_CRC64
|
# undef XZ_INTERNAL_CRC64
|
||||||
# define XZ_INTERNAL_CRC64 0
|
# define XZ_INTERNAL_CRC64 0
|
||||||
#endif
|
#endif
|
||||||
#ifndef XZ_INTERNAL_CRC64
|
#ifndef XZ_INTERNAL_CRC64
|
||||||
# ifdef __KERNEL__
|
# ifdef __KERNEL__
|
||||||
# error Using CRC64 in the kernel has not been implemented.
|
# error Using CRC64 in the kernel has not been implemented.
|
||||||
# else
|
# else
|
||||||
# define XZ_INTERNAL_CRC64 1
|
# define XZ_INTERNAL_CRC64 1
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if XZ_INTERNAL_CRC32
|
#if XZ_INTERNAL_CRC32
|
||||||
|
|
|
@ -34,7 +34,7 @@ extern void simple_free(void *p);
|
||||||
#define memzero(buf, size) memset(buf, 0, size)
|
#define memzero(buf, size) memset(buf, 0, size)
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
# define min(x, y) ((x) < (y) ? (x) : (y))
|
# define min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
#endif
|
#endif
|
||||||
#define min_t(type, x, y) min(x, y)
|
#define min_t(type, x, y) min(x, y)
|
||||||
|
|
||||||
|
@ -59,52 +59,52 @@ extern void simple_free(void *p);
|
||||||
#undef __always_inline
|
#undef __always_inline
|
||||||
|
|
||||||
#ifndef __always_inline
|
#ifndef __always_inline
|
||||||
# ifdef __GNUC__
|
# ifdef __GNUC__
|
||||||
# define __always_inline \
|
# define __always_inline \
|
||||||
inline __attribute__((__always_inline__))
|
inline __attribute__((__always_inline__))
|
||||||
# else
|
# else
|
||||||
# define __always_inline inline
|
# define __always_inline inline
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Inline functions to access unaligned unsigned 32-bit integers */
|
/* Inline functions to access unaligned unsigned 32-bit integers */
|
||||||
#ifndef get_unaligned_le32
|
#ifndef get_unaligned_le32
|
||||||
static inline uint32_t get_unaligned_le32(const uint8_t *buf)
|
static inline uint32_t get_unaligned_le32(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
return (uint32_t)buf[0]
|
return (uint32_t)buf[0]
|
||||||
| ((uint32_t)buf[1] << 8)
|
| ((uint32_t)buf[1] << 8)
|
||||||
| ((uint32_t)buf[2] << 16)
|
| ((uint32_t)buf[2] << 16)
|
||||||
| ((uint32_t)buf[3] << 24);
|
| ((uint32_t)buf[3] << 24);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef get_unaligned_be32
|
#ifndef get_unaligned_be32
|
||||||
static inline uint32_t get_unaligned_be32(const uint8_t *buf)
|
static inline uint32_t get_unaligned_be32(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
return (uint32_t)(buf[0] << 24)
|
return (uint32_t)(buf[0] << 24)
|
||||||
| ((uint32_t)buf[1] << 16)
|
| ((uint32_t)buf[1] << 16)
|
||||||
| ((uint32_t)buf[2] << 8)
|
| ((uint32_t)buf[2] << 8)
|
||||||
| (uint32_t)buf[3];
|
| (uint32_t)buf[3];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef put_unaligned_le32
|
#ifndef put_unaligned_le32
|
||||||
static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
|
static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
|
||||||
{
|
{
|
||||||
buf[0] = (uint8_t)val;
|
buf[0] = (uint8_t)val;
|
||||||
buf[1] = (uint8_t)(val >> 8);
|
buf[1] = (uint8_t)(val >> 8);
|
||||||
buf[2] = (uint8_t)(val >> 16);
|
buf[2] = (uint8_t)(val >> 16);
|
||||||
buf[3] = (uint8_t)(val >> 24);
|
buf[3] = (uint8_t)(val >> 24);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef put_unaligned_be32
|
#ifndef put_unaligned_be32
|
||||||
static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
|
static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
|
||||||
{
|
{
|
||||||
buf[0] = (uint8_t)(val >> 24);
|
buf[0] = (uint8_t)(val >> 24);
|
||||||
buf[1] = (uint8_t)(val >> 16);
|
buf[1] = (uint8_t)(val >> 16);
|
||||||
buf[2] = (uint8_t)(val >> 8);
|
buf[2] = (uint8_t)(val >> 8);
|
||||||
buf[3] = (uint8_t)val;
|
buf[3] = (uint8_t)val;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
|
||||||
* could save a few bytes in code size.
|
* could save a few bytes in code size.
|
||||||
*/
|
*/
|
||||||
#ifndef get_le32
|
#ifndef get_le32
|
||||||
# define get_le32 get_unaligned_le32
|
# define get_le32 get_unaligned_le32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* See <linux/decompress/mm.h> for details.
|
* See <linux/decompress/mm.h> for details.
|
||||||
*/
|
*/
|
||||||
#ifndef STATIC_RW_DATA
|
#ifndef STATIC_RW_DATA
|
||||||
# define STATIC_RW_DATA static
|
# define STATIC_RW_DATA static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//STATIC_RW_DATA uint32_t xz_crc32_table[256];
|
//STATIC_RW_DATA uint32_t xz_crc32_table[256];
|
||||||
|
@ -31,31 +31,31 @@ extern const uint32_t crc32Tab[256];
|
||||||
XZ_EXTERN void xz_crc32_init(void)
|
XZ_EXTERN void xz_crc32_init(void)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
const uint32_t poly = 0xEDB88320;
|
const uint32_t poly = 0xEDB88320;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
uint32_t r;
|
uint32_t r;
|
||||||
|
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; ++i) {
|
||||||
r = i;
|
r = i;
|
||||||
for (j = 0; j < 8; ++j)
|
for (j = 0; j < 8; ++j)
|
||||||
r = (r >> 1) ^ (poly & ~((r & 1) - 1));
|
r = (r >> 1) ^ (poly & ~((r & 1) - 1));
|
||||||
|
|
||||||
xz_crc32_table[i] = r;
|
xz_crc32_table[i] = r;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
XZ_EXTERN uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||||
{
|
{
|
||||||
crc = ~crc;
|
crc = ~crc;
|
||||||
|
|
||||||
while (size != 0) {
|
while (size != 0) {
|
||||||
crc = crc32Tab[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
|
crc = crc32Tab[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
|
||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,38 +13,38 @@
|
||||||
#include "xz_private.h"
|
#include "xz_private.h"
|
||||||
|
|
||||||
#ifndef STATIC_RW_DATA
|
#ifndef STATIC_RW_DATA
|
||||||
# define STATIC_RW_DATA static
|
# define STATIC_RW_DATA static
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC_RW_DATA uint64_t xz_crc64_table[256];
|
STATIC_RW_DATA uint64_t xz_crc64_table[256];
|
||||||
|
|
||||||
XZ_EXTERN void xz_crc64_init(void)
|
XZ_EXTERN void xz_crc64_init(void)
|
||||||
{
|
{
|
||||||
const uint64_t poly = 0xC96C5795D7870F42;
|
const uint64_t poly = 0xC96C5795D7870F42;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
uint64_t r;
|
uint64_t r;
|
||||||
|
|
||||||
for (i = 0; i < 256; ++i) {
|
for (i = 0; i < 256; ++i) {
|
||||||
r = i;
|
r = i;
|
||||||
for (j = 0; j < 8; ++j)
|
for (j = 0; j < 8; ++j)
|
||||||
r = (r >> 1) ^ (poly & ~((r & 1) - 1));
|
r = (r >> 1) ^ (poly & ~((r & 1) - 1));
|
||||||
|
|
||||||
xz_crc64_table[i] = r;
|
xz_crc64_table[i] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
|
XZ_EXTERN uint64_t xz_crc64(const uint8_t *buf, size_t size, uint64_t crc)
|
||||||
{
|
{
|
||||||
crc = ~crc;
|
crc = ~crc;
|
||||||
|
|
||||||
while (size != 0) {
|
while (size != 0) {
|
||||||
crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
|
crc = xz_crc64_table[*buf++ ^ (crc & 0xFF)] ^ (crc >> 8);
|
||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,62 +17,62 @@
|
||||||
#ifdef XZ_DEC_BCJ
|
#ifdef XZ_DEC_BCJ
|
||||||
|
|
||||||
struct xz_dec_bcj {
|
struct xz_dec_bcj {
|
||||||
/* Type of the BCJ filter being used */
|
/* Type of the BCJ filter being used */
|
||||||
enum {
|
enum {
|
||||||
BCJ_X86 = 4, /* x86 or x86-64 */
|
BCJ_X86 = 4, /* x86 or x86-64 */
|
||||||
BCJ_POWERPC = 5, /* Big endian only */
|
BCJ_POWERPC = 5, /* Big endian only */
|
||||||
BCJ_IA64 = 6, /* Big or little endian */
|
BCJ_IA64 = 6, /* Big or little endian */
|
||||||
BCJ_ARM = 7, /* Little endian only */
|
BCJ_ARM = 7, /* Little endian only */
|
||||||
BCJ_ARMTHUMB = 8, /* Little endian only */
|
BCJ_ARMTHUMB = 8, /* Little endian only */
|
||||||
BCJ_SPARC = 9 /* Big or little endian */
|
BCJ_SPARC = 9 /* Big or little endian */
|
||||||
} type;
|
} type;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return value of the next filter in the chain. We need to preserve
|
* Return value of the next filter in the chain. We need to preserve
|
||||||
* this information across calls, because we must not call the next
|
* this information across calls, because we must not call the next
|
||||||
* filter anymore once it has returned XZ_STREAM_END.
|
* filter anymore once it has returned XZ_STREAM_END.
|
||||||
*/
|
*/
|
||||||
enum xz_ret ret;
|
enum xz_ret ret;
|
||||||
|
|
||||||
/* True if we are operating in single-call mode. */
|
/* True if we are operating in single-call mode. */
|
||||||
bool single_call;
|
bool single_call;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Absolute position relative to the beginning of the uncompressed
|
* Absolute position relative to the beginning of the uncompressed
|
||||||
* data (in a single .xz Block). We care only about the lowest 32
|
* data (in a single .xz Block). We care only about the lowest 32
|
||||||
* bits so this doesn't need to be uint64_t even with big files.
|
* bits so this doesn't need to be uint64_t even with big files.
|
||||||
*/
|
*/
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
|
|
||||||
/* x86 filter state */
|
/* x86 filter state */
|
||||||
uint32_t x86_prev_mask;
|
uint32_t x86_prev_mask;
|
||||||
|
|
||||||
/* Temporary space to hold the variables from struct xz_buf */
|
/* Temporary space to hold the variables from struct xz_buf */
|
||||||
uint8_t *out;
|
uint8_t *out;
|
||||||
size_t out_pos;
|
size_t out_pos;
|
||||||
size_t out_size;
|
size_t out_size;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
/* Amount of already filtered data in the beginning of buf */
|
/* Amount of already filtered data in the beginning of buf */
|
||||||
size_t filtered;
|
size_t filtered;
|
||||||
|
|
||||||
/* Total amount of data currently stored in buf */
|
/* Total amount of data currently stored in buf */
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buffer to hold a mix of filtered and unfiltered data. This
|
* Buffer to hold a mix of filtered and unfiltered data. This
|
||||||
* needs to be big enough to hold Alignment + 2 * Look-ahead:
|
* needs to be big enough to hold Alignment + 2 * Look-ahead:
|
||||||
*
|
*
|
||||||
* Type Alignment Look-ahead
|
* Type Alignment Look-ahead
|
||||||
* x86 1 4
|
* x86 1 4
|
||||||
* PowerPC 4 0
|
* PowerPC 4 0
|
||||||
* IA-64 16 0
|
* IA-64 16 0
|
||||||
* ARM 4 0
|
* ARM 4 0
|
||||||
* ARM-Thumb 2 2
|
* ARM-Thumb 2 2
|
||||||
* SPARC 4 0
|
* SPARC 4 0
|
||||||
*/
|
*/
|
||||||
uint8_t buf[16];
|
uint8_t buf[16];
|
||||||
} temp;
|
} temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef XZ_DEC_X86
|
#ifdef XZ_DEC_X86
|
||||||
|
@ -82,255 +82,255 @@ struct xz_dec_bcj {
|
||||||
*/
|
*/
|
||||||
static inline int bcj_x86_test_msbyte(uint8_t b)
|
static inline int bcj_x86_test_msbyte(uint8_t b)
|
||||||
{
|
{
|
||||||
return b == 0x00 || b == 0xFF;
|
return b == 0x00 || b == 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_x86(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
static const bool mask_to_allowed_status[8]
|
static const bool mask_to_allowed_status[8]
|
||||||
= { true, true, true, false, true, false, false, false };
|
= { true, true, true, false, true, false, false, false };
|
||||||
|
|
||||||
static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
|
static const uint8_t mask_to_bit_num[8] = { 0, 1, 2, 2, 3, 3, 3, 3 };
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t prev_pos = (size_t)-1;
|
size_t prev_pos = (size_t)-1;
|
||||||
uint32_t prev_mask = s->x86_prev_mask;
|
uint32_t prev_mask = s->x86_prev_mask;
|
||||||
uint32_t src;
|
uint32_t src;
|
||||||
uint32_t dest;
|
uint32_t dest;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
|
|
||||||
if (size <= 4)
|
if (size <= 4)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
size -= 4;
|
size -= 4;
|
||||||
for (i = 0; i < size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
if ((buf[i] & 0xFE) != 0xE8)
|
if ((buf[i] & 0xFE) != 0xE8)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
prev_pos = i - prev_pos;
|
prev_pos = i - prev_pos;
|
||||||
if (prev_pos > 3) {
|
if (prev_pos > 3) {
|
||||||
prev_mask = 0;
|
prev_mask = 0;
|
||||||
} else {
|
} else {
|
||||||
prev_mask = (prev_mask << (prev_pos - 1)) & 7;
|
prev_mask = (prev_mask << (prev_pos - 1)) & 7;
|
||||||
if (prev_mask != 0) {
|
if (prev_mask != 0) {
|
||||||
b = buf[i + 4 - mask_to_bit_num[prev_mask]];
|
b = buf[i + 4 - mask_to_bit_num[prev_mask]];
|
||||||
if (!mask_to_allowed_status[prev_mask]
|
if (!mask_to_allowed_status[prev_mask]
|
||||||
|| bcj_x86_test_msbyte(b)) {
|
|| bcj_x86_test_msbyte(b)) {
|
||||||
prev_pos = i;
|
prev_pos = i;
|
||||||
prev_mask = (prev_mask << 1) | 1;
|
prev_mask = (prev_mask << 1) | 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_pos = i;
|
prev_pos = i;
|
||||||
|
|
||||||
if (bcj_x86_test_msbyte(buf[i + 4])) {
|
if (bcj_x86_test_msbyte(buf[i + 4])) {
|
||||||
src = get_unaligned_le32(buf + i + 1);
|
src = get_unaligned_le32(buf + i + 1);
|
||||||
while (true) {
|
while (true) {
|
||||||
dest = src - (s->pos + (uint32_t)i + 5);
|
dest = src - (s->pos + (uint32_t)i + 5);
|
||||||
if (prev_mask == 0)
|
if (prev_mask == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
j = mask_to_bit_num[prev_mask] * 8;
|
j = mask_to_bit_num[prev_mask] * 8;
|
||||||
b = (uint8_t)(dest >> (24 - j));
|
b = (uint8_t)(dest >> (24 - j));
|
||||||
if (!bcj_x86_test_msbyte(b))
|
if (!bcj_x86_test_msbyte(b))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
|
src = dest ^ (((uint32_t)1 << (32 - j)) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
dest &= 0x01FFFFFF;
|
dest &= 0x01FFFFFF;
|
||||||
dest |= (uint32_t)0 - (dest & 0x01000000);
|
dest |= (uint32_t)0 - (dest & 0x01000000);
|
||||||
put_unaligned_le32(dest, buf + i + 1);
|
put_unaligned_le32(dest, buf + i + 1);
|
||||||
i += 4;
|
i += 4;
|
||||||
} else {
|
} else {
|
||||||
prev_mask = (prev_mask << 1) | 1;
|
prev_mask = (prev_mask << 1) | 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_pos = i - prev_pos;
|
prev_pos = i - prev_pos;
|
||||||
s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
|
s->x86_prev_mask = prev_pos > 3 ? 0 : prev_mask << (prev_pos - 1);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_POWERPC
|
#ifdef XZ_DEC_POWERPC
|
||||||
static size_t bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_powerpc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t instr;
|
uint32_t instr;
|
||||||
|
|
||||||
for (i = 0; i + 4 <= size; i += 4) {
|
for (i = 0; i + 4 <= size; i += 4) {
|
||||||
instr = get_unaligned_be32(buf + i);
|
instr = get_unaligned_be32(buf + i);
|
||||||
if ((instr & 0xFC000003) == 0x48000001) {
|
if ((instr & 0xFC000003) == 0x48000001) {
|
||||||
instr &= 0x03FFFFFC;
|
instr &= 0x03FFFFFC;
|
||||||
instr -= s->pos + (uint32_t)i;
|
instr -= s->pos + (uint32_t)i;
|
||||||
instr &= 0x03FFFFFC;
|
instr &= 0x03FFFFFC;
|
||||||
instr |= 0x48000001;
|
instr |= 0x48000001;
|
||||||
put_unaligned_be32(instr, buf + i);
|
put_unaligned_be32(instr, buf + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_IA64
|
#ifdef XZ_DEC_IA64
|
||||||
static size_t bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_ia64(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
static const uint8_t branch_table[32] = {
|
static const uint8_t branch_table[32] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
4, 4, 6, 6, 0, 0, 7, 7,
|
4, 4, 6, 6, 0, 0, 7, 7,
|
||||||
4, 4, 0, 0, 4, 4, 0, 0
|
4, 4, 0, 0, 4, 4, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The local variables take a little bit stack space, but it's less
|
* The local variables take a little bit stack space, but it's less
|
||||||
* than what LZMA2 decoder takes, so it doesn't make sense to reduce
|
* than what LZMA2 decoder takes, so it doesn't make sense to reduce
|
||||||
* stack usage here without doing that for the LZMA2 decoder too.
|
* stack usage here without doing that for the LZMA2 decoder too.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Loop counters */
|
/* Loop counters */
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
/* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
|
/* Instruction slot (0, 1, or 2) in the 128-bit instruction word */
|
||||||
uint32_t slot;
|
uint32_t slot;
|
||||||
|
|
||||||
/* Bitwise offset of the instruction indicated by slot */
|
/* Bitwise offset of the instruction indicated by slot */
|
||||||
uint32_t bit_pos;
|
uint32_t bit_pos;
|
||||||
|
|
||||||
/* bit_pos split into byte and bit parts */
|
/* bit_pos split into byte and bit parts */
|
||||||
uint32_t byte_pos;
|
uint32_t byte_pos;
|
||||||
uint32_t bit_res;
|
uint32_t bit_res;
|
||||||
|
|
||||||
/* Address part of an instruction */
|
/* Address part of an instruction */
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
/* Mask used to detect which instructions to convert */
|
/* Mask used to detect which instructions to convert */
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
|
|
||||||
/* 41-bit instruction stored somewhere in the lowest 48 bits */
|
/* 41-bit instruction stored somewhere in the lowest 48 bits */
|
||||||
uint64_t instr;
|
uint64_t instr;
|
||||||
|
|
||||||
/* Instruction normalized with bit_res for easier manipulation */
|
/* Instruction normalized with bit_res for easier manipulation */
|
||||||
uint64_t norm;
|
uint64_t norm;
|
||||||
|
|
||||||
for (i = 0; i + 16 <= size; i += 16) {
|
for (i = 0; i + 16 <= size; i += 16) {
|
||||||
mask = branch_table[buf[i] & 0x1F];
|
mask = branch_table[buf[i] & 0x1F];
|
||||||
for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
|
for (slot = 0, bit_pos = 5; slot < 3; ++slot, bit_pos += 41) {
|
||||||
if (((mask >> slot) & 1) == 0)
|
if (((mask >> slot) & 1) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
byte_pos = bit_pos >> 3;
|
byte_pos = bit_pos >> 3;
|
||||||
bit_res = bit_pos & 7;
|
bit_res = bit_pos & 7;
|
||||||
instr = 0;
|
instr = 0;
|
||||||
for (j = 0; j < 6; ++j)
|
for (j = 0; j < 6; ++j)
|
||||||
instr |= (uint64_t)(buf[i + j + byte_pos])
|
instr |= (uint64_t)(buf[i + j + byte_pos])
|
||||||
<< (8 * j);
|
<< (8 * j);
|
||||||
|
|
||||||
norm = instr >> bit_res;
|
norm = instr >> bit_res;
|
||||||
|
|
||||||
if (((norm >> 37) & 0x0F) == 0x05
|
if (((norm >> 37) & 0x0F) == 0x05
|
||||||
&& ((norm >> 9) & 0x07) == 0) {
|
&& ((norm >> 9) & 0x07) == 0) {
|
||||||
addr = (norm >> 13) & 0x0FFFFF;
|
addr = (norm >> 13) & 0x0FFFFF;
|
||||||
addr |= ((uint32_t)(norm >> 36) & 1) << 20;
|
addr |= ((uint32_t)(norm >> 36) & 1) << 20;
|
||||||
addr <<= 4;
|
addr <<= 4;
|
||||||
addr -= s->pos + (uint32_t)i;
|
addr -= s->pos + (uint32_t)i;
|
||||||
addr >>= 4;
|
addr >>= 4;
|
||||||
|
|
||||||
norm &= ~((uint64_t)0x8FFFFF << 13);
|
norm &= ~((uint64_t)0x8FFFFF << 13);
|
||||||
norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
|
norm |= (uint64_t)(addr & 0x0FFFFF) << 13;
|
||||||
norm |= (uint64_t)(addr & 0x100000)
|
norm |= (uint64_t)(addr & 0x100000)
|
||||||
<< (36 - 20);
|
<< (36 - 20);
|
||||||
|
|
||||||
instr &= (1 << bit_res) - 1;
|
instr &= (1 << bit_res) - 1;
|
||||||
instr |= norm << bit_res;
|
instr |= norm << bit_res;
|
||||||
|
|
||||||
for (j = 0; j < 6; j++)
|
for (j = 0; j < 6; j++)
|
||||||
buf[i + j + byte_pos]
|
buf[i + j + byte_pos]
|
||||||
= (uint8_t)(instr >> (8 * j));
|
= (uint8_t)(instr >> (8 * j));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_ARM
|
#ifdef XZ_DEC_ARM
|
||||||
static size_t bcj_arm(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_arm(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
for (i = 0; i + 4 <= size; i += 4) {
|
for (i = 0; i + 4 <= size; i += 4) {
|
||||||
if (buf[i + 3] == 0xEB) {
|
if (buf[i + 3] == 0xEB) {
|
||||||
addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
|
addr = (uint32_t)buf[i] | ((uint32_t)buf[i + 1] << 8)
|
||||||
| ((uint32_t)buf[i + 2] << 16);
|
| ((uint32_t)buf[i + 2] << 16);
|
||||||
addr <<= 2;
|
addr <<= 2;
|
||||||
addr -= s->pos + (uint32_t)i + 8;
|
addr -= s->pos + (uint32_t)i + 8;
|
||||||
addr >>= 2;
|
addr >>= 2;
|
||||||
buf[i] = (uint8_t)addr;
|
buf[i] = (uint8_t)addr;
|
||||||
buf[i + 1] = (uint8_t)(addr >> 8);
|
buf[i + 1] = (uint8_t)(addr >> 8);
|
||||||
buf[i + 2] = (uint8_t)(addr >> 16);
|
buf[i + 2] = (uint8_t)(addr >> 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_ARMTHUMB
|
#ifdef XZ_DEC_ARMTHUMB
|
||||||
static size_t bcj_armthumb(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_armthumb(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
for (i = 0; i + 4 <= size; i += 2) {
|
for (i = 0; i + 4 <= size; i += 2) {
|
||||||
if ((buf[i + 1] & 0xF8) == 0xF0
|
if ((buf[i + 1] & 0xF8) == 0xF0
|
||||||
&& (buf[i + 3] & 0xF8) == 0xF8) {
|
&& (buf[i + 3] & 0xF8) == 0xF8) {
|
||||||
addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
|
addr = (((uint32_t)buf[i + 1] & 0x07) << 19)
|
||||||
| ((uint32_t)buf[i] << 11)
|
| ((uint32_t)buf[i] << 11)
|
||||||
| (((uint32_t)buf[i + 3] & 0x07) << 8)
|
| (((uint32_t)buf[i + 3] & 0x07) << 8)
|
||||||
| (uint32_t)buf[i + 2];
|
| (uint32_t)buf[i + 2];
|
||||||
addr <<= 1;
|
addr <<= 1;
|
||||||
addr -= s->pos + (uint32_t)i + 4;
|
addr -= s->pos + (uint32_t)i + 4;
|
||||||
addr >>= 1;
|
addr >>= 1;
|
||||||
buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
|
buf[i + 1] = (uint8_t)(0xF0 | ((addr >> 19) & 0x07));
|
||||||
buf[i] = (uint8_t)(addr >> 11);
|
buf[i] = (uint8_t)(addr >> 11);
|
||||||
buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
|
buf[i + 3] = (uint8_t)(0xF8 | ((addr >> 8) & 0x07));
|
||||||
buf[i + 2] = (uint8_t)addr;
|
buf[i + 2] = (uint8_t)addr;
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_SPARC
|
#ifdef XZ_DEC_SPARC
|
||||||
static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
uint32_t instr;
|
uint32_t instr;
|
||||||
|
|
||||||
for (i = 0; i + 4 <= size; i += 4) {
|
for (i = 0; i + 4 <= size; i += 4) {
|
||||||
instr = get_unaligned_be32(buf + i);
|
instr = get_unaligned_be32(buf + i);
|
||||||
if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
|
if ((instr >> 22) == 0x100 || (instr >> 22) == 0x1FF) {
|
||||||
instr <<= 2;
|
instr <<= 2;
|
||||||
instr -= s->pos + (uint32_t)i;
|
instr -= s->pos + (uint32_t)i;
|
||||||
instr >>= 2;
|
instr >>= 2;
|
||||||
instr = ((uint32_t)0x40000000 - (instr & 0x400000))
|
instr = ((uint32_t)0x40000000 - (instr & 0x400000))
|
||||||
| 0x40000000 | (instr & 0x3FFFFF);
|
| 0x40000000 | (instr & 0x3FFFFF);
|
||||||
put_unaligned_be32(instr, buf + i);
|
put_unaligned_be32(instr, buf + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -343,52 +343,52 @@ static size_t bcj_sparc(struct xz_dec_bcj *s, uint8_t *buf, size_t size)
|
||||||
* avoid pointers to static data (at least on x86).
|
* avoid pointers to static data (at least on x86).
|
||||||
*/
|
*/
|
||||||
static void bcj_apply(struct xz_dec_bcj *s,
|
static void bcj_apply(struct xz_dec_bcj *s,
|
||||||
uint8_t *buf, size_t *pos, size_t size)
|
uint8_t *buf, size_t *pos, size_t size)
|
||||||
{
|
{
|
||||||
size_t filtered;
|
size_t filtered;
|
||||||
|
|
||||||
buf += *pos;
|
buf += *pos;
|
||||||
size -= *pos;
|
size -= *pos;
|
||||||
|
|
||||||
switch (s->type) {
|
switch (s->type) {
|
||||||
#ifdef XZ_DEC_X86
|
#ifdef XZ_DEC_X86
|
||||||
case BCJ_X86:
|
case BCJ_X86:
|
||||||
filtered = bcj_x86(s, buf, size);
|
filtered = bcj_x86(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_POWERPC
|
#ifdef XZ_DEC_POWERPC
|
||||||
case BCJ_POWERPC:
|
case BCJ_POWERPC:
|
||||||
filtered = bcj_powerpc(s, buf, size);
|
filtered = bcj_powerpc(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_IA64
|
#ifdef XZ_DEC_IA64
|
||||||
case BCJ_IA64:
|
case BCJ_IA64:
|
||||||
filtered = bcj_ia64(s, buf, size);
|
filtered = bcj_ia64(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_ARM
|
#ifdef XZ_DEC_ARM
|
||||||
case BCJ_ARM:
|
case BCJ_ARM:
|
||||||
filtered = bcj_arm(s, buf, size);
|
filtered = bcj_arm(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_ARMTHUMB
|
#ifdef XZ_DEC_ARMTHUMB
|
||||||
case BCJ_ARMTHUMB:
|
case BCJ_ARMTHUMB:
|
||||||
filtered = bcj_armthumb(s, buf, size);
|
filtered = bcj_armthumb(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_SPARC
|
#ifdef XZ_DEC_SPARC
|
||||||
case BCJ_SPARC:
|
case BCJ_SPARC:
|
||||||
filtered = bcj_sparc(s, buf, size);
|
filtered = bcj_sparc(s, buf, size);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
/* Never reached but silence compiler warnings. */
|
/* Never reached but silence compiler warnings. */
|
||||||
filtered = 0;
|
filtered = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*pos += filtered;
|
*pos += filtered;
|
||||||
s->pos += filtered;
|
s->pos += filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -398,15 +398,15 @@ static void bcj_apply(struct xz_dec_bcj *s,
|
||||||
*/
|
*/
|
||||||
static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
|
static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
|
||||||
{
|
{
|
||||||
size_t copy_size;
|
size_t copy_size;
|
||||||
|
|
||||||
copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
|
copy_size = min_t(size_t, s->temp.filtered, b->out_size - b->out_pos);
|
||||||
memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
|
memcpy(b->out + b->out_pos, s->temp.buf, copy_size);
|
||||||
b->out_pos += copy_size;
|
b->out_pos += copy_size;
|
||||||
|
|
||||||
s->temp.filtered -= copy_size;
|
s->temp.filtered -= copy_size;
|
||||||
s->temp.size -= copy_size;
|
s->temp.size -= copy_size;
|
||||||
memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
|
memmove(s->temp.buf, s->temp.buf + copy_size, s->temp.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -415,160 +415,160 @@ static void bcj_flush(struct xz_dec_bcj *s, struct xz_buf *b)
|
||||||
* some buffering.
|
* some buffering.
|
||||||
*/
|
*/
|
||||||
XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
|
XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||||
struct xz_dec_lzma2 *lzma2,
|
struct xz_dec_lzma2 *lzma2,
|
||||||
struct xz_buf *b)
|
struct xz_buf *b)
|
||||||
{
|
{
|
||||||
size_t out_start;
|
size_t out_start;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flush pending already filtered data to the output buffer. Return
|
* Flush pending already filtered data to the output buffer. Return
|
||||||
* immediatelly if we couldn't flush everything, or if the next
|
* immediatelly if we couldn't flush everything, or if the next
|
||||||
* filter in the chain had already returned XZ_STREAM_END.
|
* filter in the chain had already returned XZ_STREAM_END.
|
||||||
*/
|
*/
|
||||||
if (s->temp.filtered > 0) {
|
if (s->temp.filtered > 0) {
|
||||||
bcj_flush(s, b);
|
bcj_flush(s, b);
|
||||||
if (s->temp.filtered > 0)
|
if (s->temp.filtered > 0)
|
||||||
return XZ_OK;
|
return XZ_OK;
|
||||||
|
|
||||||
if (s->ret == XZ_STREAM_END)
|
if (s->ret == XZ_STREAM_END)
|
||||||
return XZ_STREAM_END;
|
return XZ_STREAM_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have more output space than what is currently pending in
|
* If we have more output space than what is currently pending in
|
||||||
* temp, copy the unfiltered data from temp to the output buffer
|
* temp, copy the unfiltered data from temp to the output buffer
|
||||||
* and try to fill the output buffer by decoding more data from the
|
* and try to fill the output buffer by decoding more data from the
|
||||||
* next filter in the chain. Apply the BCJ filter on the new data
|
* next filter in the chain. Apply the BCJ filter on the new data
|
||||||
* in the output buffer. If everything cannot be filtered, copy it
|
* in the output buffer. If everything cannot be filtered, copy it
|
||||||
* to temp and rewind the output buffer position accordingly.
|
* to temp and rewind the output buffer position accordingly.
|
||||||
*
|
*
|
||||||
* This needs to be always run when temp.size == 0 to handle a special
|
* This needs to be always run when temp.size == 0 to handle a special
|
||||||
* case where the output buffer is full and the next filter has no
|
* case where the output buffer is full and the next filter has no
|
||||||
* more output coming but hasn't returned XZ_STREAM_END yet.
|
* more output coming but hasn't returned XZ_STREAM_END yet.
|
||||||
*/
|
*/
|
||||||
if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
|
if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) {
|
||||||
out_start = b->out_pos;
|
out_start = b->out_pos;
|
||||||
memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
|
memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size);
|
||||||
b->out_pos += s->temp.size;
|
b->out_pos += s->temp.size;
|
||||||
|
|
||||||
s->ret = xz_dec_lzma2_run(lzma2, b);
|
s->ret = xz_dec_lzma2_run(lzma2, b);
|
||||||
if (s->ret != XZ_STREAM_END
|
if (s->ret != XZ_STREAM_END
|
||||||
&& (s->ret != XZ_OK || s->single_call))
|
&& (s->ret != XZ_OK || s->single_call))
|
||||||
return s->ret;
|
return s->ret;
|
||||||
|
|
||||||
bcj_apply(s, b->out, &out_start, b->out_pos);
|
bcj_apply(s, b->out, &out_start, b->out_pos);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* As an exception, if the next filter returned XZ_STREAM_END,
|
* As an exception, if the next filter returned XZ_STREAM_END,
|
||||||
* we can do that too, since the last few bytes that remain
|
* we can do that too, since the last few bytes that remain
|
||||||
* unfiltered are meant to remain unfiltered.
|
* unfiltered are meant to remain unfiltered.
|
||||||
*/
|
*/
|
||||||
if (s->ret == XZ_STREAM_END)
|
if (s->ret == XZ_STREAM_END)
|
||||||
return XZ_STREAM_END;
|
return XZ_STREAM_END;
|
||||||
|
|
||||||
s->temp.size = b->out_pos - out_start;
|
s->temp.size = b->out_pos - out_start;
|
||||||
b->out_pos -= s->temp.size;
|
b->out_pos -= s->temp.size;
|
||||||
memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
|
memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there wasn't enough input to the next filter to fill
|
* If there wasn't enough input to the next filter to fill
|
||||||
* the output buffer with unfiltered data, there's no point
|
* the output buffer with unfiltered data, there's no point
|
||||||
* to try decoding more data to temp.
|
* to try decoding more data to temp.
|
||||||
*/
|
*/
|
||||||
if (b->out_pos + s->temp.size < b->out_size)
|
if (b->out_pos + s->temp.size < b->out_size)
|
||||||
return XZ_OK;
|
return XZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We have unfiltered data in temp. If the output buffer isn't full
|
* We have unfiltered data in temp. If the output buffer isn't full
|
||||||
* yet, try to fill the temp buffer by decoding more data from the
|
* yet, try to fill the temp buffer by decoding more data from the
|
||||||
* next filter. Apply the BCJ filter on temp. Then we hopefully can
|
* next filter. Apply the BCJ filter on temp. Then we hopefully can
|
||||||
* fill the actual output buffer by copying filtered data from temp.
|
* fill the actual output buffer by copying filtered data from temp.
|
||||||
* A mix of filtered and unfiltered data may be left in temp; it will
|
* A mix of filtered and unfiltered data may be left in temp; it will
|
||||||
* be taken care on the next call to this function.
|
* be taken care on the next call to this function.
|
||||||
*/
|
*/
|
||||||
if (b->out_pos < b->out_size) {
|
if (b->out_pos < b->out_size) {
|
||||||
/* Make b->out{,_pos,_size} temporarily point to s->temp. */
|
/* Make b->out{,_pos,_size} temporarily point to s->temp. */
|
||||||
s->out = b->out;
|
s->out = b->out;
|
||||||
s->out_pos = b->out_pos;
|
s->out_pos = b->out_pos;
|
||||||
s->out_size = b->out_size;
|
s->out_size = b->out_size;
|
||||||
b->out = s->temp.buf;
|
b->out = s->temp.buf;
|
||||||
b->out_pos = s->temp.size;
|
b->out_pos = s->temp.size;
|
||||||
b->out_size = sizeof(s->temp.buf);
|
b->out_size = sizeof(s->temp.buf);
|
||||||
|
|
||||||
s->ret = xz_dec_lzma2_run(lzma2, b);
|
s->ret = xz_dec_lzma2_run(lzma2, b);
|
||||||
|
|
||||||
s->temp.size = b->out_pos;
|
s->temp.size = b->out_pos;
|
||||||
b->out = s->out;
|
b->out = s->out;
|
||||||
b->out_pos = s->out_pos;
|
b->out_pos = s->out_pos;
|
||||||
b->out_size = s->out_size;
|
b->out_size = s->out_size;
|
||||||
|
|
||||||
if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
|
if (s->ret != XZ_OK && s->ret != XZ_STREAM_END)
|
||||||
return s->ret;
|
return s->ret;
|
||||||
|
|
||||||
bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
|
bcj_apply(s, s->temp.buf, &s->temp.filtered, s->temp.size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the next filter returned XZ_STREAM_END, we mark that
|
* If the next filter returned XZ_STREAM_END, we mark that
|
||||||
* everything is filtered, since the last unfiltered bytes
|
* everything is filtered, since the last unfiltered bytes
|
||||||
* of the stream are meant to be left as is.
|
* of the stream are meant to be left as is.
|
||||||
*/
|
*/
|
||||||
if (s->ret == XZ_STREAM_END)
|
if (s->ret == XZ_STREAM_END)
|
||||||
s->temp.filtered = s->temp.size;
|
s->temp.filtered = s->temp.size;
|
||||||
|
|
||||||
bcj_flush(s, b);
|
bcj_flush(s, b);
|
||||||
if (s->temp.filtered > 0)
|
if (s->temp.filtered > 0)
|
||||||
return XZ_OK;
|
return XZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s->ret;
|
return s->ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call)
|
XZ_EXTERN struct xz_dec_bcj *xz_dec_bcj_create(bool single_call)
|
||||||
{
|
{
|
||||||
struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
|
struct xz_dec_bcj *s = kmalloc(sizeof(*s), GFP_KERNEL);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
s->single_call = single_call;
|
s->single_call = single_call;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id)
|
XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id)
|
||||||
{
|
{
|
||||||
switch (id) {
|
switch (id) {
|
||||||
#ifdef XZ_DEC_X86
|
#ifdef XZ_DEC_X86
|
||||||
case BCJ_X86:
|
case BCJ_X86:
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_POWERPC
|
#ifdef XZ_DEC_POWERPC
|
||||||
case BCJ_POWERPC:
|
case BCJ_POWERPC:
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_IA64
|
#ifdef XZ_DEC_IA64
|
||||||
case BCJ_IA64:
|
case BCJ_IA64:
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_ARM
|
#ifdef XZ_DEC_ARM
|
||||||
case BCJ_ARM:
|
case BCJ_ARM:
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_ARMTHUMB
|
#ifdef XZ_DEC_ARMTHUMB
|
||||||
case BCJ_ARMTHUMB:
|
case BCJ_ARMTHUMB:
|
||||||
#endif
|
#endif
|
||||||
#ifdef XZ_DEC_SPARC
|
#ifdef XZ_DEC_SPARC
|
||||||
case BCJ_SPARC:
|
case BCJ_SPARC:
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Unsupported Filter ID */
|
/* Unsupported Filter ID */
|
||||||
return XZ_OPTIONS_ERROR;
|
return XZ_OPTIONS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->type = id;
|
s->type = id;
|
||||||
s->ret = XZ_OK;
|
s->ret = XZ_OK;
|
||||||
s->pos = 0;
|
s->pos = 0;
|
||||||
s->x86_prev_mask = 0;
|
s->x86_prev_mask = 0;
|
||||||
s->temp.filtered = 0;
|
s->temp.filtered = 0;
|
||||||
s->temp.size = 0;
|
s->temp.size = 0;
|
||||||
|
|
||||||
return XZ_OK;
|
return XZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -50,9 +50,9 @@ static uint8_t buffer_out[1024];
|
||||||
* A few of the fields are never modified so we initialize them here.
|
* A few of the fields are never modified so we initialize them here.
|
||||||
*/
|
*/
|
||||||
static struct xz_buf buffers = {
|
static struct xz_buf buffers = {
|
||||||
.in = buffer_in,
|
.in = buffer_in,
|
||||||
.out = buffer_out,
|
.out = buffer_out,
|
||||||
.out_size = sizeof(buffer_out)
|
.out_size = sizeof(buffer_out)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -63,32 +63,32 @@ static uint32_t crc;
|
||||||
|
|
||||||
static int xz_dec_test_open(struct inode *i, struct file *f)
|
static int xz_dec_test_open(struct inode *i, struct file *f)
|
||||||
{
|
{
|
||||||
if (device_is_open)
|
if (device_is_open)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
device_is_open = true;
|
device_is_open = true;
|
||||||
|
|
||||||
xz_dec_reset(state);
|
xz_dec_reset(state);
|
||||||
ret = XZ_OK;
|
ret = XZ_OK;
|
||||||
crc = 0xFFFFFFFF;
|
crc = 0xFFFFFFFF;
|
||||||
|
|
||||||
buffers.in_pos = 0;
|
buffers.in_pos = 0;
|
||||||
buffers.in_size = 0;
|
buffers.in_size = 0;
|
||||||
buffers.out_pos = 0;
|
buffers.out_pos = 0;
|
||||||
|
|
||||||
printk(KERN_INFO DEVICE_NAME ": opened\n");
|
printk(KERN_INFO DEVICE_NAME ": opened\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xz_dec_test_release(struct inode *i, struct file *f)
|
static int xz_dec_test_release(struct inode *i, struct file *f)
|
||||||
{
|
{
|
||||||
device_is_open = false;
|
device_is_open = false;
|
||||||
|
|
||||||
if (ret == XZ_OK)
|
if (ret == XZ_OK)
|
||||||
printk(KERN_INFO DEVICE_NAME ": input was truncated\n");
|
printk(KERN_INFO DEVICE_NAME ": input was truncated\n");
|
||||||
|
|
||||||
printk(KERN_INFO DEVICE_NAME ": closed\n");
|
printk(KERN_INFO DEVICE_NAME ": closed\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -100,110 +100,110 @@ static int xz_dec_test_release(struct inode *i, struct file *f)
|
||||||
* after the first Stream is considered to be garbage.
|
* after the first Stream is considered to be garbage.
|
||||||
*/
|
*/
|
||||||
static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
|
static ssize_t xz_dec_test_write(struct file *file, const char __user *buf,
|
||||||
size_t size, loff_t *pos)
|
size_t size, loff_t *pos)
|
||||||
{
|
{
|
||||||
size_t remaining;
|
size_t remaining;
|
||||||
|
|
||||||
if (ret != XZ_OK) {
|
if (ret != XZ_OK) {
|
||||||
if (size > 0)
|
if (size > 0)
|
||||||
printk(KERN_INFO DEVICE_NAME ": %zu bytes of "
|
printk(KERN_INFO DEVICE_NAME ": %zu bytes of "
|
||||||
"garbage at the end of the file\n",
|
"garbage at the end of the file\n",
|
||||||
size);
|
size);
|
||||||
|
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO DEVICE_NAME ": decoding %zu bytes of input\n",
|
printk(KERN_INFO DEVICE_NAME ": decoding %zu bytes of input\n",
|
||||||
size);
|
size);
|
||||||
|
|
||||||
remaining = size;
|
remaining = size;
|
||||||
while ((remaining > 0 || buffers.out_pos == buffers.out_size)
|
while ((remaining > 0 || buffers.out_pos == buffers.out_size)
|
||||||
&& ret == XZ_OK) {
|
&& ret == XZ_OK) {
|
||||||
if (buffers.in_pos == buffers.in_size) {
|
if (buffers.in_pos == buffers.in_size) {
|
||||||
buffers.in_pos = 0;
|
buffers.in_pos = 0;
|
||||||
buffers.in_size = min(remaining, sizeof(buffer_in));
|
buffers.in_size = min(remaining, sizeof(buffer_in));
|
||||||
if (copy_from_user(buffer_in, buf, buffers.in_size))
|
if (copy_from_user(buffer_in, buf, buffers.in_size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
buf += buffers.in_size;
|
buf += buffers.in_size;
|
||||||
remaining -= buffers.in_size;
|
remaining -= buffers.in_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffers.out_pos = 0;
|
buffers.out_pos = 0;
|
||||||
ret = xz_dec_run(state, &buffers);
|
ret = xz_dec_run(state, &buffers);
|
||||||
crc = crc32(crc, buffer_out, buffers.out_pos);
|
crc = crc32(crc, buffer_out, buffers.out_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case XZ_OK:
|
case XZ_OK:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_OK\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_OK\n");
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
case XZ_STREAM_END:
|
case XZ_STREAM_END:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_STREAM_END, "
|
printk(KERN_INFO DEVICE_NAME ": XZ_STREAM_END, "
|
||||||
"CRC32 = 0x%08X\n", ~crc);
|
"CRC32 = 0x%08X\n", ~crc);
|
||||||
return size - remaining - (buffers.in_size - buffers.in_pos);
|
return size - remaining - (buffers.in_size - buffers.in_pos);
|
||||||
|
|
||||||
case XZ_MEMLIMIT_ERROR:
|
case XZ_MEMLIMIT_ERROR:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_MEMLIMIT_ERROR\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_MEMLIMIT_ERROR\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XZ_FORMAT_ERROR:
|
case XZ_FORMAT_ERROR:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_FORMAT_ERROR\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_FORMAT_ERROR\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XZ_OPTIONS_ERROR:
|
case XZ_OPTIONS_ERROR:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_OPTIONS_ERROR\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_OPTIONS_ERROR\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XZ_DATA_ERROR:
|
case XZ_DATA_ERROR:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_DATA_ERROR\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_DATA_ERROR\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XZ_BUF_ERROR:
|
case XZ_BUF_ERROR:
|
||||||
printk(KERN_INFO DEVICE_NAME ": XZ_BUF_ERROR\n");
|
printk(KERN_INFO DEVICE_NAME ": XZ_BUF_ERROR\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printk(KERN_INFO DEVICE_NAME ": Bug detected!\n");
|
printk(KERN_INFO DEVICE_NAME ": Bug detected!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate the XZ decoder state and register the character device. */
|
/* Allocate the XZ decoder state and register the character device. */
|
||||||
static int __init xz_dec_test_init(void)
|
static int __init xz_dec_test_init(void)
|
||||||
{
|
{
|
||||||
static const struct file_operations fileops = {
|
static const struct file_operations fileops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.open = &xz_dec_test_open,
|
.open = &xz_dec_test_open,
|
||||||
.release = &xz_dec_test_release,
|
.release = &xz_dec_test_release,
|
||||||
.write = &xz_dec_test_write
|
.write = &xz_dec_test_write
|
||||||
};
|
};
|
||||||
|
|
||||||
state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
|
state = xz_dec_init(XZ_PREALLOC, DICT_MAX);
|
||||||
if (state == NULL)
|
if (state == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
device_major = register_chrdev(0, DEVICE_NAME, &fileops);
|
device_major = register_chrdev(0, DEVICE_NAME, &fileops);
|
||||||
if (device_major < 0) {
|
if (device_major < 0) {
|
||||||
xz_dec_end(state);
|
xz_dec_end(state);
|
||||||
return device_major;
|
return device_major;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(KERN_INFO DEVICE_NAME ": module loaded\n");
|
printk(KERN_INFO DEVICE_NAME ": module loaded\n");
|
||||||
printk(KERN_INFO DEVICE_NAME ": Create a device node with "
|
printk(KERN_INFO DEVICE_NAME ": Create a device node with "
|
||||||
"'mknod " DEVICE_NAME " c %d 0' and write .xz files "
|
"'mknod " DEVICE_NAME " c %d 0' and write .xz files "
|
||||||
"to it.\n", device_major);
|
"to it.\n", device_major);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit xz_dec_test_exit(void)
|
static void __exit xz_dec_test_exit(void)
|
||||||
{
|
{
|
||||||
unregister_chrdev(device_major, DEVICE_NAME);
|
unregister_chrdev(device_major, DEVICE_NAME);
|
||||||
xz_dec_end(state);
|
xz_dec_end(state);
|
||||||
printk(KERN_INFO DEVICE_NAME ": module unloaded\n");
|
printk(KERN_INFO DEVICE_NAME ": module unloaded\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(xz_dec_test_init);
|
module_init(xz_dec_test_init);
|
||||||
|
|
|
@ -25,34 +25,34 @@ int xz_uncompress_init(struct xz_buf *stream, uint8_t *sbuf, uint8_t *dbuf)
|
||||||
stream->out_pos = 0;
|
stream->out_pos = 0;
|
||||||
stream->out_size = 0;
|
stream->out_size = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xz_uncompress_stream(struct xz_buf *stream, uint8_t *sbuf, uint32_t slen,
|
int xz_uncompress_stream(struct xz_buf *stream, uint8_t *sbuf, uint32_t slen,
|
||||||
uint8_t *dbuf, uint32_t dlen, uint32_t *decomp_len)
|
uint8_t *dbuf, uint32_t dlen, uint32_t *decomp_len)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
*decomp_len = 0;
|
*decomp_len = 0;
|
||||||
|
|
||||||
if (stream->in_pos == stream->in_size) {
|
if (stream->in_pos == stream->in_size) {
|
||||||
stream->in_size = slen;
|
stream->in_size = slen;
|
||||||
stream->in_pos = 0;
|
stream->in_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stream->out_pos == stream->out_size) {
|
if (stream->out_pos == stream->out_size) {
|
||||||
stream->out_size = dlen;
|
stream->out_size = dlen;
|
||||||
stream->out_pos = 0;
|
stream->out_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = xz_dec_run(s, stream);
|
status = xz_dec_run(s, stream);
|
||||||
|
|
||||||
if ((status == XZ_STREAM_END) || (stream->out_pos == stream->out_size))
|
if ((status == XZ_STREAM_END) || (stream->out_pos == stream->out_size))
|
||||||
*decomp_len = stream->out_pos;
|
*decomp_len = stream->out_pos;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void xz_uncompress_end()
|
void xz_uncompress_end()
|
||||||
{
|
{
|
||||||
xz_dec_end(s);
|
xz_dec_end(s);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,18 +40,18 @@
|
||||||
* either short or long repeated match, and NONLIT means any non-literal.
|
* either short or long repeated match, and NONLIT means any non-literal.
|
||||||
*/
|
*/
|
||||||
enum lzma_state {
|
enum lzma_state {
|
||||||
STATE_LIT_LIT,
|
STATE_LIT_LIT,
|
||||||
STATE_MATCH_LIT_LIT,
|
STATE_MATCH_LIT_LIT,
|
||||||
STATE_REP_LIT_LIT,
|
STATE_REP_LIT_LIT,
|
||||||
STATE_SHORTREP_LIT_LIT,
|
STATE_SHORTREP_LIT_LIT,
|
||||||
STATE_MATCH_LIT,
|
STATE_MATCH_LIT,
|
||||||
STATE_REP_LIT,
|
STATE_REP_LIT,
|
||||||
STATE_SHORTREP_LIT,
|
STATE_SHORTREP_LIT,
|
||||||
STATE_LIT_MATCH,
|
STATE_LIT_MATCH,
|
||||||
STATE_LIT_LONGREP,
|
STATE_LIT_LONGREP,
|
||||||
STATE_LIT_SHORTREP,
|
STATE_LIT_SHORTREP,
|
||||||
STATE_NONLIT_MATCH,
|
STATE_NONLIT_MATCH,
|
||||||
STATE_NONLIT_REP
|
STATE_NONLIT_REP
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Total number of states */
|
/* Total number of states */
|
||||||
|
@ -63,36 +63,36 @@ enum lzma_state {
|
||||||
/* Indicate that the latest symbol was a literal. */
|
/* Indicate that the latest symbol was a literal. */
|
||||||
static inline void lzma_state_literal(enum lzma_state *state)
|
static inline void lzma_state_literal(enum lzma_state *state)
|
||||||
{
|
{
|
||||||
if (*state <= STATE_SHORTREP_LIT_LIT)
|
if (*state <= STATE_SHORTREP_LIT_LIT)
|
||||||
*state = STATE_LIT_LIT;
|
*state = STATE_LIT_LIT;
|
||||||
else if (*state <= STATE_LIT_SHORTREP)
|
else if (*state <= STATE_LIT_SHORTREP)
|
||||||
*state -= 3;
|
*state -= 3;
|
||||||
else
|
else
|
||||||
*state -= 6;
|
*state -= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indicate that the latest symbol was a match. */
|
/* Indicate that the latest symbol was a match. */
|
||||||
static inline void lzma_state_match(enum lzma_state *state)
|
static inline void lzma_state_match(enum lzma_state *state)
|
||||||
{
|
{
|
||||||
*state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
|
*state = *state < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indicate that the latest state was a long repeated match. */
|
/* Indicate that the latest state was a long repeated match. */
|
||||||
static inline void lzma_state_long_rep(enum lzma_state *state)
|
static inline void lzma_state_long_rep(enum lzma_state *state)
|
||||||
{
|
{
|
||||||
*state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
|
*state = *state < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indicate that the latest symbol was a short match. */
|
/* Indicate that the latest symbol was a short match. */
|
||||||
static inline void lzma_state_short_rep(enum lzma_state *state)
|
static inline void lzma_state_short_rep(enum lzma_state *state)
|
||||||
{
|
{
|
||||||
*state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
|
*state = *state < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test if the previous symbol was a literal. */
|
/* Test if the previous symbol was a literal. */
|
||||||
static inline bool lzma_state_is_literal(enum lzma_state state)
|
static inline bool lzma_state_is_literal(enum lzma_state state)
|
||||||
{
|
{
|
||||||
return state < LIT_STATES;
|
return state < LIT_STATES;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Each literal coder is divided in three sections:
|
/* Each literal coder is divided in three sections:
|
||||||
|
@ -146,8 +146,8 @@ static inline bool lzma_state_is_literal(enum lzma_state state)
|
||||||
*/
|
*/
|
||||||
static inline uint32_t lzma_get_dist_state(uint32_t len)
|
static inline uint32_t lzma_get_dist_state(uint32_t len)
|
||||||
{
|
{
|
||||||
return len < DIST_STATES + MATCH_LEN_MIN
|
return len < DIST_STATES + MATCH_LEN_MIN
|
||||||
? len - MATCH_LEN_MIN : DIST_STATES - 1;
|
? len - MATCH_LEN_MIN : DIST_STATES - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -11,51 +11,51 @@
|
||||||
#define XZ_PRIVATE_H
|
#define XZ_PRIVATE_H
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
# include <linux/xz.h>
|
# include <linux/xz.h>
|
||||||
# include <linux/kernel.h>
|
# include <linux/kernel.h>
|
||||||
# include <asm/unaligned.h>
|
# include <asm/unaligned.h>
|
||||||
/* XZ_PREBOOT may be defined only via decompress_unxz.c. */
|
/* XZ_PREBOOT may be defined only via decompress_unxz.c. */
|
||||||
# ifndef XZ_PREBOOT
|
# ifndef XZ_PREBOOT
|
||||||
# include <linux/slab.h>
|
# include <linux/slab.h>
|
||||||
# include <linux/vmalloc.h>
|
# include <linux/vmalloc.h>
|
||||||
# include <linux/string.h>
|
# include <linux/string.h>
|
||||||
# ifdef CONFIG_XZ_DEC_X86
|
# ifdef CONFIG_XZ_DEC_X86
|
||||||
# define XZ_DEC_X86
|
# define XZ_DEC_X86
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_XZ_DEC_POWERPC
|
# ifdef CONFIG_XZ_DEC_POWERPC
|
||||||
# define XZ_DEC_POWERPC
|
# define XZ_DEC_POWERPC
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_XZ_DEC_IA64
|
# ifdef CONFIG_XZ_DEC_IA64
|
||||||
# define XZ_DEC_IA64
|
# define XZ_DEC_IA64
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_XZ_DEC_ARM
|
# ifdef CONFIG_XZ_DEC_ARM
|
||||||
# define XZ_DEC_ARM
|
# define XZ_DEC_ARM
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_XZ_DEC_ARMTHUMB
|
# ifdef CONFIG_XZ_DEC_ARMTHUMB
|
||||||
# define XZ_DEC_ARMTHUMB
|
# define XZ_DEC_ARMTHUMB
|
||||||
# endif
|
# endif
|
||||||
# ifdef CONFIG_XZ_DEC_SPARC
|
# ifdef CONFIG_XZ_DEC_SPARC
|
||||||
# define XZ_DEC_SPARC
|
# define XZ_DEC_SPARC
|
||||||
# endif
|
# endif
|
||||||
# define memeq(a, b, size) (memcmp(a, b, size) == 0)
|
# define memeq(a, b, size) (memcmp(a, b, size) == 0)
|
||||||
# define memzero(buf, size) memset(buf, 0, size)
|
# define memzero(buf, size) memset(buf, 0, size)
|
||||||
# endif
|
# endif
|
||||||
# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
|
# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* For userspace builds, use a separate header to define the required
|
* For userspace builds, use a separate header to define the required
|
||||||
* macros and functions. This makes it easier to adapt the code into
|
* macros and functions. This makes it easier to adapt the code into
|
||||||
* different environments and avoids clutter in the Linux kernel tree.
|
* different environments and avoids clutter in the Linux kernel tree.
|
||||||
*/
|
*/
|
||||||
# include "xz_config.h"
|
# include "xz_config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If no specific decoding mode is requested, enable support for all modes. */
|
/* If no specific decoding mode is requested, enable support for all modes. */
|
||||||
#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
|
#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
|
||||||
&& !defined(XZ_DEC_DYNALLOC)
|
&& !defined(XZ_DEC_DYNALLOC)
|
||||||
# define XZ_DEC_SINGLE
|
# define XZ_DEC_SINGLE
|
||||||
# define XZ_DEC_PREALLOC
|
# define XZ_DEC_PREALLOC
|
||||||
# define XZ_DEC_DYNALLOC
|
# define XZ_DEC_DYNALLOC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -64,29 +64,29 @@
|
||||||
* false at compile time and thus allow the compiler to omit unneeded code.
|
* false at compile time and thus allow the compiler to omit unneeded code.
|
||||||
*/
|
*/
|
||||||
#ifdef XZ_DEC_SINGLE
|
#ifdef XZ_DEC_SINGLE
|
||||||
# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
|
# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
|
||||||
#else
|
#else
|
||||||
# define DEC_IS_SINGLE(mode) (false)
|
# define DEC_IS_SINGLE(mode) (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_PREALLOC
|
#ifdef XZ_DEC_PREALLOC
|
||||||
# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
|
# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
|
||||||
#else
|
#else
|
||||||
# define DEC_IS_PREALLOC(mode) (false)
|
# define DEC_IS_PREALLOC(mode) (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XZ_DEC_DYNALLOC
|
#ifdef XZ_DEC_DYNALLOC
|
||||||
# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
|
# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
|
||||||
#else
|
#else
|
||||||
# define DEC_IS_DYNALLOC(mode) (false)
|
# define DEC_IS_DYNALLOC(mode) (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(XZ_DEC_SINGLE)
|
#if !defined(XZ_DEC_SINGLE)
|
||||||
# define DEC_IS_MULTI(mode) (true)
|
# define DEC_IS_MULTI(mode) (true)
|
||||||
#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
|
#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
|
||||||
# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
|
# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
|
||||||
#else
|
#else
|
||||||
# define DEC_IS_MULTI(mode) (false)
|
# define DEC_IS_MULTI(mode) (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -94,12 +94,12 @@
|
||||||
* XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
|
* XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
|
||||||
*/
|
*/
|
||||||
#ifndef XZ_DEC_BCJ
|
#ifndef XZ_DEC_BCJ
|
||||||
# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
|
# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
|
||||||
|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
|
|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
|
||||||
|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
|
|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
|
||||||
|| defined(XZ_DEC_SPARC)
|
|| defined(XZ_DEC_SPARC)
|
||||||
# define XZ_DEC_BCJ
|
# define XZ_DEC_BCJ
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
* before calling xz_dec_lzma2_run().
|
* before calling xz_dec_lzma2_run().
|
||||||
*/
|
*/
|
||||||
XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
|
XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
|
||||||
uint32_t dict_max);
|
uint32_t dict_max);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decode the LZMA2 properties (one byte) and reset the decoder. Return
|
* Decode the LZMA2 properties (one byte) and reset the decoder. Return
|
||||||
|
@ -116,11 +116,11 @@ XZ_EXTERN struct xz_dec_lzma2 *xz_dec_lzma2_create(enum xz_mode mode,
|
||||||
* decoder doesn't support.
|
* decoder doesn't support.
|
||||||
*/
|
*/
|
||||||
XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
|
XZ_EXTERN enum xz_ret xz_dec_lzma2_reset(struct xz_dec_lzma2 *s,
|
||||||
uint8_t props);
|
uint8_t props);
|
||||||
|
|
||||||
/* Decode raw LZMA2 stream from b->in to b->out. */
|
/* Decode raw LZMA2 stream from b->in to b->out. */
|
||||||
XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
|
XZ_EXTERN enum xz_ret xz_dec_lzma2_run(struct xz_dec_lzma2 *s,
|
||||||
struct xz_buf *b);
|
struct xz_buf *b);
|
||||||
|
|
||||||
/* Free the memory allocated for the LZMA2 decoder. */
|
/* Free the memory allocated for the LZMA2 decoder. */
|
||||||
XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
|
XZ_EXTERN void xz_dec_lzma2_end(struct xz_dec_lzma2 *s);
|
||||||
|
@ -146,8 +146,8 @@ XZ_EXTERN enum xz_ret xz_dec_bcj_reset(struct xz_dec_bcj *s, uint8_t id);
|
||||||
* must be called directly.
|
* must be called directly.
|
||||||
*/
|
*/
|
||||||
XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
|
XZ_EXTERN enum xz_ret xz_dec_bcj_run(struct xz_dec_bcj *s,
|
||||||
struct xz_dec_lzma2 *lzma2,
|
struct xz_dec_lzma2 *lzma2,
|
||||||
struct xz_buf *b);
|
struct xz_buf *b);
|
||||||
|
|
||||||
/* Free the memory allocated for the BCJ filters. */
|
/* Free the memory allocated for the BCJ filters. */
|
||||||
#define xz_dec_bcj_end(s) kfree(s)
|
#define xz_dec_bcj_end(s) kfree(s)
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
#define XZ_STREAM_H
|
#define XZ_STREAM_H
|
||||||
|
|
||||||
#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
|
#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
|
||||||
# include <linux/crc32.h>
|
# include <linux/crc32.h>
|
||||||
# undef crc32
|
# undef crc32
|
||||||
# define xz_crc32(buf, size, crc) \
|
# define xz_crc32(buf, size, crc) \
|
||||||
(~crc32_le(~(uint32_t)(crc), buf, size))
|
(~crc32_le(~(uint32_t)(crc), buf, size))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -50,10 +50,10 @@ typedef uint64_t vli_type;
|
||||||
|
|
||||||
/* Integrity Check types */
|
/* Integrity Check types */
|
||||||
enum xz_check {
|
enum xz_check {
|
||||||
XZ_CHECK_NONE = 0,
|
XZ_CHECK_NONE = 0,
|
||||||
XZ_CHECK_CRC32 = 1,
|
XZ_CHECK_CRC32 = 1,
|
||||||
XZ_CHECK_CRC64 = 4,
|
XZ_CHECK_CRC64 = 4,
|
||||||
XZ_CHECK_SHA256 = 10
|
XZ_CHECK_SHA256 = 10
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Maximum possible Check ID */
|
/* Maximum possible Check ID */
|
||||||
|
|
|
@ -152,32 +152,32 @@ typedef enum
|
||||||
/**
|
/**
|
||||||
* @brief BL602 Memory Map Definitions
|
* @brief BL602 Memory Map Definitions
|
||||||
*/
|
*/
|
||||||
#define BL602_FLASH_XIP_BASE 0x23000000
|
#define BL602_FLASH_XIP_BASE 0x23000000
|
||||||
#define BL602_FLASH_XIP_END (0x23000000+16*1024*1024)
|
#define BL602_FLASH_XIP_END (0x23000000+16*1024*1024)
|
||||||
#define BL602_FLASH_XIP_REMAP0_BASE 0x33000000
|
#define BL602_FLASH_XIP_REMAP0_BASE 0x33000000
|
||||||
#define BL602_FLASH_XIP_REMAP0_END (0x33000000+16*1024*1024)
|
#define BL602_FLASH_XIP_REMAP0_END (0x33000000+16*1024*1024)
|
||||||
#define BL602_FLASH_XIP_REMAP1_BASE 0x43000000
|
#define BL602_FLASH_XIP_REMAP1_BASE 0x43000000
|
||||||
#define BL602_FLASH_XIP_REMAP1_END (0x43000000+16*1024*1024)
|
#define BL602_FLASH_XIP_REMAP1_END (0x43000000+16*1024*1024)
|
||||||
#define BL602_FLASH_XIP_REMAP2_BASE 0x53000000
|
#define BL602_FLASH_XIP_REMAP2_BASE 0x53000000
|
||||||
#define BL602_FLASH_XIP_REMAP2_END (0x53000000+16*1024*1024)
|
#define BL602_FLASH_XIP_REMAP2_END (0x53000000+16*1024*1024)
|
||||||
|
|
||||||
#define BL602_WRAM_BASE 0x42020000
|
#define BL602_WRAM_BASE 0x42020000
|
||||||
#define BL602_WRAM_END (0x42020000+176*1024)
|
#define BL602_WRAM_END (0x42020000+176*1024)
|
||||||
#define BL602_WRAM_REMAP0_BASE 0x22020000
|
#define BL602_WRAM_REMAP0_BASE 0x22020000
|
||||||
#define BL602_WRAM_REMAP0_END (0x22020000+176*1024)
|
#define BL602_WRAM_REMAP0_END (0x22020000+176*1024)
|
||||||
#define BL602_WRAM_REMAP1_BASE 0x32020000
|
#define BL602_WRAM_REMAP1_BASE 0x32020000
|
||||||
#define BL602_WRAM_REMAP1_END (0x32020000+176*1024)
|
#define BL602_WRAM_REMAP1_END (0x32020000+176*1024)
|
||||||
#define BL602_WRAM_REMAP2_BASE 0x52020000
|
#define BL602_WRAM_REMAP2_BASE 0x52020000
|
||||||
#define BL602_WRAM_REMAP2_END (0x52020000+176*1024)
|
#define BL602_WRAM_REMAP2_END (0x52020000+176*1024)
|
||||||
|
|
||||||
#define BL602_TCM_BASE 0x22008000
|
#define BL602_TCM_BASE 0x22008000
|
||||||
#define BL602_TCM_END (0x22008000+(96+176)*1024)
|
#define BL602_TCM_END (0x22008000+(96+176)*1024)
|
||||||
#define BL602_TCM_REMAP0_BASE 0x32008000
|
#define BL602_TCM_REMAP0_BASE 0x32008000
|
||||||
#define BL602_TCM_REMAP0_END (0x32008000+(96+176)*1024)
|
#define BL602_TCM_REMAP0_END (0x32008000+(96+176)*1024)
|
||||||
#define BL602_TCM_REMAP1_BASE 0x42008000
|
#define BL602_TCM_REMAP1_BASE 0x42008000
|
||||||
#define BL602_TCM_REMAP1_END (0x42008000+(96+176)*1024)
|
#define BL602_TCM_REMAP1_END (0x42008000+(96+176)*1024)
|
||||||
#define BL602_TCM_REMAP2_BASE 0x52008000
|
#define BL602_TCM_REMAP2_BASE 0x52008000
|
||||||
#define BL602_TCM_REMAP2_END (0x52008000+(96+176)*1024)
|
#define BL602_TCM_REMAP2_END (0x52008000+(96+176)*1024)
|
||||||
/*@} end of group Memory_Map_Section */
|
/*@} end of group Memory_Map_Section */
|
||||||
|
|
||||||
/* BL602 peripherals base address */
|
/* BL602 peripherals base address */
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
#define __IRQ_ALIGN64 __attribute__((interrupt,aligned(64)))
|
#define __IRQ_ALIGN64 __attribute__((interrupt,aligned(64)))
|
||||||
#endif
|
#endif
|
||||||
#ifndef ALIGN4
|
#ifndef ALIGN4
|
||||||
#define ALIGN4 __attribute((aligned (4)))
|
#define ALIGN4 __attribute((aligned (4)))
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
\brief No Operation
|
\brief No Operation
|
||||||
|
@ -122,7 +122,7 @@ extern void clic_clear_pending(uint32_t source);
|
||||||
|
|
||||||
#define NVIC_ClearPendingIRQ clic_clear_pending
|
#define NVIC_ClearPendingIRQ clic_clear_pending
|
||||||
|
|
||||||
//#define __set_MSP(val) __ASM volatile ("lw sp,0(%0)":: "r"(val))
|
//#define __set_MSP(val) __ASM volatile ("lw sp,0(%0)":: "r"(val))
|
||||||
#define __set_MSP(msp) __ASM volatile ("add sp, x0, %0":: "r"(msp))
|
#define __set_MSP(msp) __ASM volatile ("add sp, x0, %0":: "r"(msp))
|
||||||
|
|
||||||
#endif /* __CMSIS_COMPATIBLE_GCC_H */
|
#endif /* __CMSIS_COMPATIBLE_GCC_H */
|
||||||
|
|
|
@ -107,7 +107,7 @@ const pFunc __Vectors[] __attribute__ ((section(".init"),aligned(64))) = {
|
||||||
I2C_IRQHandler, /* 16 + 32 */
|
I2C_IRQHandler, /* 16 + 32 */
|
||||||
0, /* 16 + 33 */
|
0, /* 16 + 33 */
|
||||||
PWM_IRQHandler, /* 16 + 34 */
|
PWM_IRQHandler, /* 16 + 34 */
|
||||||
0, /* 16 + 35 */
|
0, /* 16 + 35 */
|
||||||
TIMER_CH0_IRQHandler, /* 16 + 36 */
|
TIMER_CH0_IRQHandler, /* 16 + 36 */
|
||||||
TIMER_CH1_IRQHandler, /* 16 + 37 */
|
TIMER_CH1_IRQHandler, /* 16 + 37 */
|
||||||
TIMER_WDT_IRQHandler, /* 16 + 38 */
|
TIMER_WDT_IRQHandler, /* 16 + 38 */
|
||||||
|
@ -127,8 +127,8 @@ const pFunc __Vectors[] __attribute__ ((section(".init"),aligned(64))) = {
|
||||||
HBN_OUT1_IRQHandler, /* 16 + 52 */
|
HBN_OUT1_IRQHandler, /* 16 + 52 */
|
||||||
BOR_IRQHandler, /* 16 + 53 */
|
BOR_IRQHandler, /* 16 + 53 */
|
||||||
WIFI_IRQHandler, /* 16 + 54 */
|
WIFI_IRQHandler, /* 16 + 54 */
|
||||||
BZ_PHY_IRQHandler, /* 16 + 55 */
|
BZ_PHY_IRQHandler, /* 16 + 55 */
|
||||||
BLE_IRQHandler, /* 16 + 56 */
|
BLE_IRQHandler, /* 16 + 56 */
|
||||||
MAC_TXRX_TIMER_IRQHandler, /* 16 + 57 */
|
MAC_TXRX_TIMER_IRQHandler, /* 16 + 57 */
|
||||||
MAC_TXRX_MISC_IRQHandler, /* 16 + 58 */
|
MAC_TXRX_MISC_IRQHandler, /* 16 + 58 */
|
||||||
MAC_RX_TRG_IRQHandler, /* 16 + 59 */
|
MAC_RX_TRG_IRQHandler, /* 16 + 59 */
|
||||||
|
|
0
components/bl602/bl602_std/bl602_std/StdDriver/Inc/bl602_mfg_flash.h
Executable file → Normal file
0
components/bl602/bl602_std/bl602_std/StdDriver/Inc/bl602_mfg_flash.h
Executable file → Normal file
0
components/bl602/bl602_std/bl602_std/StdDriver/Inc/bl602_mfg_media.h
Executable file → Normal file
0
components/bl602/bl602_std/bl602_std/StdDriver/Inc/bl602_mfg_media.h
Executable file → Normal file
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user