#include <string.h>
-byte *
-xstrdup(byte *s)
+char *
+xstrdup(const char *s)
{
uns l = strlen(s) + 1;
return memcpy(xmalloc(l), s, l);
}
uns
-base224_encode(byte *dest, byte *src, uns len)
+base224_encode(byte *dest, const byte *src, uns len)
{
u32 lo=0, hi=0; /* 64-bit buffer accumulating input bits */
uns i=0; /* How many source bits do we have buffered */
}
uns
-base224_decode(byte *dest, byte *src, uns len)
+base224_decode(byte *dest, const byte *src, uns len)
{
u32 hi=0, lo=0; /* 64-bit buffer accumulating output bits */
uns i=0; /* How many bits do we have accumulated */
* of the GNU Lesser General Public License.
*/
-uns base224_encode(byte *dest, byte *src, uns len);
-uns base224_decode(byte *dest, byte *src, uns len);
+uns base224_encode(byte *dest, const byte *src, uns len);
+uns base224_decode(byte *dest, const byte *src, uns len);
/*
* Warning: when encoding, at least 4 bytes of extra space are needed.
#include <string.h>
-static byte base64_table[] =
+static const byte base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
-static byte base64_pad = '=';
+static const byte base64_pad = '=';
uns
-base64_encode(byte *dest, byte *src, uns len)
+base64_encode(byte *dest, const byte *src, uns len)
{
- byte *current = src;
+ const byte *current = src;
uns i = 0;
while (len > 2) { /* keep going until we have less than 24 bits */
/* as above, but backwards. :) */
uns
-base64_decode(byte *dest, byte *src, uns len)
+base64_decode(byte *dest, const byte *src, uns len)
{
- byte *current = src;
+ const byte *current = src;
uns ch;
uns i = 0, j = 0;
static byte reverse_table[256];
* of the GNU Lesser General Public License.
*/
-uns base64_encode(byte *dest, byte *src, uns len);
-uns base64_decode(byte *dest, byte *src, uns len);
+uns base64_encode(byte *dest, const byte *src, uns len);
+uns base64_decode(byte *dest, const byte *src, uns len);
/*
* Use this macro to calculate buffer size.
#include <stdio.h>
char *
-bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args)
+bb_vprintf_at(bb_t *bb, uns ofs, const char *fmt, va_list args)
{
bb_grow(bb, ofs + 1);
va_list args2;
}
char *
-bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...)
+bb_printf_at(bb_t *bb, uns ofs, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
}
char *
-bb_vprintf(bb_t *bb, char *fmt, va_list args)
+bb_vprintf(bb_t *bb, const char *fmt, va_list args)
{
return bb_vprintf_at(bb, 0, fmt, args);
}
char *
-bb_printf(bb_t *bb, char *fmt, ...)
+bb_printf(bb_t *bb, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
#define GBUF_PREFIX(x) bb_##x
#include "lib/gbuf.h"
-char *bb_vprintf(bb_t *bb, char *fmt, va_list args);
-char *bb_printf(bb_t *bb, char *fmt, ...);
-char *bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args);
-char *bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...);
+char *bb_vprintf(bb_t *bb, const char *fmt, va_list args);
+char *bb_printf(bb_t *bb, const char *fmt, ...);
+char *bb_vprintf_at(bb_t *bb, uns ofs, const char *fmt, va_list args);
+char *bb_printf_at(bb_t *bb, uns ofs, const char *fmt, ...);
#endif
}
int
-careful_write(int fd, void *buf, int len)
+careful_write(int fd, const void *buf, int len)
{
- byte *pos = buf;
+ const byte *pos = buf;
while (len)
{
int l = write(fd, pos, len);
};
static const struct unit *
-lookup_unit(byte *value, byte *end, byte **msg)
+lookup_unit(const byte *value, const byte *end, byte **msg)
{
if (end && *end) {
if (end == value || end[1] || *end >= '0' && *end <= '9')
static char cf_rngerr[] = "Number out of range";
byte *
-cf_parse_int(byte *str, int *ptr)
+cf_parse_int(const byte *str, int *ptr)
{
byte *msg = NULL;
if (!*str)
}
byte *
-cf_parse_u64(byte *str, u64 *ptr)
+cf_parse_u64(const byte *str, u64 *ptr)
{
byte *msg = NULL;
if (!*str)
}
byte *
-cf_parse_double(byte *str, double *ptr)
+cf_parse_double(const byte *str, double *ptr)
{
byte *msg = NULL;
if (!*str)
}
byte *
-cf_parse_ip(byte *p, u32 *varp)
+cf_parse_ip(const byte *p, u32 *varp)
{
if (!*p)
return "Missing IP address";
void cf_init_section(byte *name, struct cf_section *sec, void *ptr, uns do_bzero);
/* Parsers for basic types: conf-parse.c */
-byte *cf_parse_int(byte *str, int *ptr);
-byte *cf_parse_u64(byte *str, u64 *ptr);
-byte *cf_parse_double(byte *str, double *ptr);
-byte *cf_parse_ip(byte *p, u32 *varp);
+byte *cf_parse_int(const byte *str, int *ptr);
+byte *cf_parse_u64(const byte *str, u64 *ptr);
+byte *cf_parse_double(const byte *str, double *ptr);
+byte *cf_parse_ip(const byte *p, u32 *varp);
#endif
#include "lib/chartype.h"
int
-match_ct_patt(byte *p, byte *t)
+match_ct_patt(const char *p, const char *t)
{
if (*p == '*' && !p[1]) /* "*" matches everything */
return 1;
struct tm;
extern void (*log_switch_hook)(struct tm *tm);
-void log_msg(unsigned int cat, const char *msg, ...) FORMAT_CHECK(printf,2,3);
+void log_msg(uns cat, const char *msg, ...) FORMAT_CHECK(printf,2,3);
#define log log_msg
-void vlog_msg(unsigned int cat, const char *msg, va_list args);
+void vlog_msg(uns cat, const char *msg, va_list args);
void die(const char *, ...) NONRET FORMAT_CHECK(printf,1,2);
-void log_init(byte *argv0);
-void log_file(byte *name);
+void log_init(const char *argv0);
+void log_file(const char *name);
void log_fork(void);
int log_switch(void);
-void assert_failed(char *assertion, char *file, int line) NONRET;
+void assert_failed(const char *assertion, const char *file, int line) NONRET;
void assert_failed_noinfo(void) NONRET;
#ifdef DEBUG_ASSERTS
* their own xmalloc and we don't want to interfere with them, hence
* the renaming.
*/
-void *xmalloc(unsigned) LIKE_MALLOC;
-void *xrealloc(void *, unsigned);
+void *xmalloc(uns) LIKE_MALLOC;
+void *xrealloc(void *, uns);
void xfree(void *);
#endif
-void *xmalloc_zero(unsigned) LIKE_MALLOC;
-byte *xstrdup(byte *) LIKE_MALLOC;
+void *xmalloc_zero(uns) LIKE_MALLOC;
+char *xstrdup(const char *) LIKE_MALLOC;
/* Content-Type pattern matching and filters */
-int match_ct_patt(byte *, byte *);
+int match_ct_patt(const char *, const char *);
/* wordsplit.c */
/* pat(i)match.c: Matching of shell patterns */
-int match_pattern(byte *, byte *);
-int match_pattern_nocase(byte *, byte *);
+int match_pattern(const char *, const char *);
+int match_pattern_nocase(const char *, const char *);
/* md5hex.c */
-void md5_to_hex(byte *, byte *);
-void hex_to_md5(byte *, byte *);
+void md5_to_hex(const byte *, byte *);
+void hex_to_md5(const byte *, byte *);
#define MD5_SIZE 16
#define MD5_HEX_SIZE 33
typedef struct regex regex;
-regex *rx_compile(byte *r, int icase);
+regex *rx_compile(const byte *r, int icase);
void rx_free(regex *r);
-int rx_match(regex *r, byte *s);
-int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
+int rx_match(regex *r, const byte *s);
+int rx_subst(regex *r, const byte *by, const byte *src, byte *dest, uns destlen);
/* random.c */
/* mmap.c */
-void *mmap_file(byte *name, unsigned *len, int writeable);
+void *mmap_file(const byte *name, unsigned *len, int writeable);
void munmap_file(void *start, unsigned len);
/* proctitle.c */
void setproctitle_init(int argc, char **argv);
-void setproctitle(char *msg, ...) FORMAT_CHECK(printf,1,2);
+void setproctitle(const char *msg, ...) FORMAT_CHECK(printf,1,2);
char *getproctitle(void);
/* randomkey.c */
/* runcmd.c */
-int run_command(byte *cmd, ...);
-void NONRET exec_command(byte *cmd, ...);
-void echo_command(byte *buf, int size, byte *cmd, ...);
-int run_command_v(byte *cmd, va_list args);
-void NONRET exec_command_v(byte *cmd, va_list args);
-void echo_command_v(byte *buf, int size, byte *cmd, va_list args);
+int run_command(const byte *cmd, ...);
+void NONRET exec_command(const byte *cmd, ...);
+void echo_command(byte *buf, int size, const byte *cmd, ...);
+int run_command_v(const byte *cmd, va_list args);
+void NONRET exec_command_v(const byte *cmd, va_list args);
+void echo_command_v(byte *buf, int size, const byte *cmd, va_list args);
/* carefulio.c */
int careful_read(int fd, void *buf, int len);
-int careful_write(int fd, void *buf, int len);
+int careful_write(int fd, const void *buf, int len);
/* sync.c */
-void sync_dir(byte *name);
+void sync_dir(const byte *name);
/* sighandler.c */
/* string.c */
-byte *str_unesc(byte *dest, byte *src);
+byte *str_unesc(byte *dest, const byte *src);
byte *str_format_flags(byte *dest, const byte *fmt, uns flags);
/* bigalloc.c */
}
void
-log_file(byte *name)
+log_file(const char *name)
{
if (name)
{
}
void
-assert_failed(char *assertion, char *file, int line)
+assert_failed(const char *assertion, const char *file, int line)
{
log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
abort();
die("Internal error: Assertion failed.");
}
-static byte *
-log_basename(byte *n)
+static const char *
+log_basename(const char *n)
{
- byte *p = n;
+ const char *p = n;
while (*n)
if (*n++ == '/')
}
void
-log_init(byte *argv0)
+log_init(const char *argv0)
{
if (argv0)
{
#include <stdio.h>
void
-md5_to_hex(byte *s, byte *d)
+md5_to_hex(const byte *s, byte *d)
{
int i;
for(i=0; i<MD5_SIZE; i++)
}
void
-hex_to_md5(byte *s, byte *d)
+hex_to_md5(const byte *s, byte *d)
{
uns i, j;
for(i=0; i<MD5_SIZE; i++)
#include <string.h>
char *
-mp_strdup(struct mempool *p, char *s)
+mp_strdup(struct mempool *p, const char *s)
{
uns l = strlen(s) + 1;
char *t = mp_alloc_fast_noalign(p, l);
}
void *
-mp_memdup(struct mempool *p, void *s, uns len)
+mp_memdup(struct mempool *p, const void *s, uns len)
{
void *t = mp_alloc_fast(p, len);
memcpy(t, s, len);
/*** mempool-str.c ***/
-char *mp_strdup(struct mempool *, char *) LIKE_MALLOC;
-void *mp_memdup(struct mempool *, void *, uns) LIKE_MALLOC;
+char *mp_strdup(struct mempool *, const char *) LIKE_MALLOC;
+void *mp_memdup(struct mempool *, const void *, uns) LIKE_MALLOC;
char *mp_multicat(struct mempool *, ...) LIKE_MALLOC SENTINEL_CHECK;
static inline char * LIKE_MALLOC
-mp_strcat(struct mempool *mp, char *x, char *y)
+mp_strcat(struct mempool *mp, const char *x, const char *y)
{
return mp_multicat(mp, x, y, NULL);
}
#include <sys/mman.h>
void *
-mmap_file(byte *name, unsigned *len, int writeable)
+mmap_file(const byte *name, unsigned *len, int writeable)
{
int fd = open(name, writeable ? O_RDWR : O_RDONLY);
struct stat st;
*/
int
-MATCH_FUNC_NAME(byte *p, byte *s)
+MATCH_FUNC_NAME(const char *p, const char *s)
{
while (*p)
{
}
void
-setproctitle(char *msg, ...)
+setproctitle(const char *msg, ...)
{
va_list args;
byte buf[256];
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(const byte *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, const byte *s)
{
int err = regexec(&r->rx, s, 10, r->matches, 0);
if (!err)
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, const byte *by, const byte *src, byte *dest, uns destlen)
{
byte *end = dest + destlen - 1;
uns j = *by++ - '0';
if (j <= r->rx.re_nsub && r->matches[j].rm_so >= 0)
{
- byte *s = src + r->matches[j].rm_so;
+ const byte *s = src + r->matches[j].rm_so;
uns i = r->matches[j].rm_eo - r->matches[j].rm_so;
if (dest + i >= end)
return -1;
#include <sys/wait.h>
void NONRET
-exec_command_v(byte *cmd, va_list args)
+exec_command_v(const byte *cmd, va_list args)
{
va_list cargs;
va_copy(cargs, args);
cnt++;
va_end(cargs);
char **argv = alloca(sizeof(byte *) * cnt);
- argv[0] = cmd;
+ argv[0] = (char *)cmd;
cnt = 1;
va_copy(cargs, args);
while (arg = va_arg(cargs, byte *))
}
int
-run_command_v(byte *cmd, va_list args)
+run_command_v(const byte *cmd, va_list args)
{
pid_t p = fork();
if (p < 0)
}
void
-echo_command_v(byte *buf, int size, byte *cmd, va_list args)
+echo_command_v(byte *buf, int size, const byte *cmd, va_list args)
{
byte *limit = buf + size - 4;
byte *p = buf;
- byte *arg = cmd;
+ const byte *arg = cmd;
do
{
int l = strlen(arg);
}
int
-run_command(byte *cmd, ...)
+run_command(const byte *cmd, ...)
{
va_list args;
va_start(args, cmd);
}
void NONRET
-exec_command(byte *cmd, ...)
+exec_command(const byte *cmd, ...)
{
va_list args;
va_start(args, cmd);
}
void
-echo_command(byte *buf, int len, byte *cmd, ...)
+echo_command(byte *buf, int len, const byte *cmd, ...)
{
va_list args;
va_start(args, cmd);
}
void
-stk_hexdump_internal(char *dst, byte *src, uns n)
+stk_hexdump_internal(char *dst, const byte *src, uns n)
{
for (uns i=0; i<n; i++)
{
#include <string.h>
#include <stdio.h>
-#define stk_strdup(s) ({ char *_s=(s); uns _l=strlen(_s)+1; char *_x=alloca(_l); memcpy(_x, _s, _l); _x; })
-#define stk_strndup(s,n) ({ char *_s=(s); uns _l=strnlen(_s,(n)); char *_x=alloca(_l+1); memcpy(_x, _s, _l); _x[_l]=0; _x; })
-#define stk_strcat(s1,s2) ({ char *_s1=(s1); char *_s2=(s2); uns _l1=strlen(_s1); uns _l2=strlen(_s2); char *_x=alloca(_l1+_l2+1); memcpy(_x,_s1,_l1); memcpy(_x+_l1,_s2,_l2+1); _x; })
-#define stk_strmulticat(s...) ({ char *_s[]={s}; char *_x=alloca(stk_array_len(_s, ARRAY_SIZE(_s)-1)); stk_array_join(_x, _s, ARRAY_SIZE(_s)-1, 0); _x; })
+#define stk_strdup(s) ({ const char *_s=(s); uns _l=strlen(_s)+1; char *_x=alloca(_l); memcpy(_x, _s, _l); _x; })
+#define stk_strndup(s,n) ({ const char *_s=(s); uns _l=strnlen(_s,(n)); char *_x=alloca(_l+1); memcpy(_x, _s, _l); _x[_l]=0; _x; })
+#define stk_strcat(s1,s2) ({ const char *_s1=(s1); const char *_s2=(s2); uns _l1=strlen(_s1); uns _l2=strlen(_s2); char *_x=alloca(_l1+_l2+1); memcpy(_x,_s1,_l1); memcpy(_x+_l1,_s2,_l2+1); _x; })
+#define stk_strmulticat(s...) ({ const char *_s[]={s}; char *_x=alloca(stk_array_len(_s, ARRAY_SIZE(_s)-1)); stk_array_join(_x, _s, ARRAY_SIZE(_s)-1, 0); _x; })
#define stk_strarraycat(s,n) ({ char **_s=(s); int _n=(n); char *_x=alloca(stk_array_len(_s,_n)); stk_array_join(_x, _s, _n, 0); _x; })
#define stk_strjoin(s,n,sep) ({ char **_s=(s); int _n=(n); char *_x=alloca(stk_array_len(_s,_n)+_n-1); stk_array_join(_x, _s, _n, (sep)); _x; })
#define stk_printf(f...) ({ uns _l=stk_printf_internal(f); char *_x=alloca(_l); sprintf(_x, f); _x; })
#define stk_vprintf(f, args) ({ uns _l=stk_vprintf_internal(f, args); char *_x=alloca(_l); vsprintf(_x, f, args); _x; })
#define stk_hexdump(s,n) ({ uns _n=(n); char *_x=alloca(3*_n+1); stk_hexdump_internal(_x,(byte*)(s),_n); _x; })
-#define stk_str_unesc(s) ({ byte *_s=(s); byte *_d=alloca(strlen(_s)+1); str_unesc(_d, _s); _d; })
+#define stk_str_unesc(s) ({ const byte *_s=(s); byte *_d=alloca(strlen(_s)+1); str_unesc(_d, _s); _d; })
uns stk_array_len(char **s, uns cnt);
void stk_array_join(char *x, char **s, uns cnt, uns sep);
uns stk_printf_internal(const char *x, ...) FORMAT_CHECK(printf,1,2);
uns stk_vprintf_internal(const char *x, va_list args);
-void stk_hexdump_internal(char *dst, byte *src, uns n);
+void stk_hexdump_internal(char *dst, const byte *src, uns n);
/* Expands C99-like escape sequences.
* It is safe to use the same buffer for both input and output. */
byte *
-str_unesc(byte *d, byte *s)
+str_unesc(byte *d, const byte *s)
{
while (*s)
{
#include <unistd.h>
void
-sync_dir(byte *name)
+sync_dir(const byte *name)
{
int fd = open(name, O_RDONLY
#ifdef CONFIG_LINUX
/* Big endian format */
#if defined(CPU_ALLOW_UNALIGNED) && defined(CPU_BIG_ENDIAN)
-static inline uns get_u16_be(byte *p) { return *(u16 *)p; }
-static inline u32 get_u32_be(byte *p) { return *(u32 *)p; }
-static inline u64 get_u64_be(byte *p) { return *(u64 *)p; }
-static inline void put_u16_be(byte *p, uns x) { *(u16 *)p = x; }
-static inline void put_u32_be(byte *p, u32 x) { *(u32 *)p = x; }
-static inline void put_u64_be(byte *p, u64 x) { *(u64 *)p = x; }
+static inline uns get_u16_be(const void *p) { return *(u16 *)p; }
+static inline u32 get_u32_be(const void *p) { return *(u32 *)p; }
+static inline u64 get_u64_be(const void *p) { return *(u64 *)p; }
+static inline void put_u16_be(void *p, uns x) { *(u16 *)p = x; }
+static inline void put_u32_be(void *p, u32 x) { *(u32 *)p = x; }
+static inline void put_u64_be(void *p, u64 x) { *(u64 *)p = x; }
#else
-static inline uns get_u16_be(byte *p)
+static inline uns get_u16_be(const void *p)
{
- return (p[0] << 8) | p[1];
+ const byte *c = p;
+ return (c[0] << 8) | c[1];
}
-static inline u32 get_u32_be(byte *p)
+static inline u32 get_u32_be(const void *p)
{
- return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
+ const byte *c = p;
+ return (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3];
}
-static inline u64 get_u64_be(byte *p)
+static inline u64 get_u64_be(const void *p)
{
- return ((u64) get_u32_be(p) << 32) | get_u32_be(p+4);
+ return ((u64) get_u32_be(p) << 32) | get_u32_be((const byte *)p+4);
}
-static inline void put_u16_be(byte *p, uns x)
+static inline void put_u16_be(void *p, uns x)
{
- p[0] = x >> 8;
- p[1] = x;
+ byte *c = p;
+ c[0] = x >> 8;
+ c[1] = x;
}
-static inline void put_u32_be(byte *p, u32 x)
+static inline void put_u32_be(void *p, u32 x)
{
- p[0] = x >> 24;
- p[1] = x >> 16;
- p[2] = x >> 8;
- p[3] = x;
+ byte *c = p;
+ c[0] = x >> 24;
+ c[1] = x >> 16;
+ c[2] = x >> 8;
+ c[3] = x;
}
-static inline void put_u64_be(byte *p, u64 x)
+static inline void put_u64_be(void *p, u64 x)
{
put_u32_be(p, x >> 32);
- put_u32_be(p+4, x);
+ put_u32_be((byte *)p+4, x);
}
#endif
/* Little-endian format */
#if defined(CPU_ALLOW_UNALIGNED) && !defined(CPU_BIG_ENDIAN)
-static inline uns get_u16_le(byte *p) { return *(u16 *)p; }
-static inline u32 get_u32_le(byte *p) { return *(u32 *)p; }
-static inline u64 get_u64_le(byte *p) { return *(u64 *)p; }
-static inline void put_u16_le(byte *p, uns x) { *(u16 *)p = x; }
-static inline void put_u32_le(byte *p, u32 x) { *(u32 *)p = x; }
-static inline void put_u64_le(byte *p, u64 x) { *(u64 *)p = x; }
+static inline uns get_u16_le(const void *p) { return *(u16 *)p; }
+static inline u32 get_u32_le(const void *p) { return *(u32 *)p; }
+static inline u64 get_u64_le(const void *p) { return *(u64 *)p; }
+static inline void put_u16_le(void *p, uns x) { *(u16 *)p = x; }
+static inline void put_u32_le(void *p, u32 x) { *(u32 *)p = x; }
+static inline void put_u64_le(void *p, u64 x) { *(u64 *)p = x; }
#else
-static inline uns get_u16_le(byte *p)
+static inline uns get_u16_le(const void *p)
{
- return p[0] | (p[1] << 8);
+ const byte *c = p;
+ return c[0] | (c[1] << 8);
}
-static inline u32 get_u32_le(byte *p)
+static inline u32 get_u32_le(const void *p)
{
- return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
+ const byte *c = p;
+ return c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24);
}
-static inline u64 get_u64_le(byte *p)
+static inline u64 get_u64_le(const void *p)
{
- return get_u32_le(p) | ((u64) get_u32_le(p+4) << 32);
+ return get_u32_le(p) | ((u64) get_u32_le((const byte *)p+4) << 32);
}
-static inline void put_u16_le(byte *p, uns x)
+static inline void put_u16_le(void *p, uns x)
{
- p[0] = x;
- p[1] = x >> 8;
+ byte *c = p;
+ c[0] = x;
+ c[1] = x >> 8;
}
-static inline void put_u32_le(byte *p, u32 x)
+static inline void put_u32_le(void *p, u32 x)
{
- p[0] = x;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
+ byte *c = p;
+ c[0] = x;
+ c[1] = x >> 8;
+ c[2] = x >> 16;
+ c[3] = x >> 24;
}
-static inline void put_u64_le(byte *p, u64 x)
+static inline void put_u64_le(void *p, u64 x)
{
put_u32_le(p, x);
- put_u32_le(p+4, x >> 32);
+ put_u32_le((byte *)p+4, x >> 32);
}
#endif
-static inline u64 get_u40_be(byte *p)
+static inline u64 get_u40_be(const void *p)
{
- return ((u64)p[0] << 32) | get_u32_be(p+1);
+ const byte *c = p;
+ return ((u64)c[0] << 32) | get_u32_be(c+1);
}
-static inline void put_u40_be(byte *p, u64 x)
+static inline void put_u40_be(void *p, u64 x)
{
- p[0] = x >> 32;
- put_u32_be(p+1, x);
+ byte *c = p;
+ c[0] = x >> 32;
+ put_u32_be(c+1, x);
}
-static inline u64 get_u40_le(byte *p)
+static inline u64 get_u40_le(const void *p)
{
- return get_u32_le(p) | ((u64) p[4] << 32);
+ const byte *c = p;
+ return get_u32_le(c) | ((u64) c[4] << 32);
}
-static inline void put_u40_le(byte *p, u64 x)
+static inline void put_u40_le(void *p, u64 x)
{
- put_u32_le(p, x);
- p[4] = x >> 32;
+ byte *c = p;
+ put_u32_le(c, x);
+ c[4] = x >> 32;
}
/* The native format */
#ifdef CPU_BIG_ENDIAN
-static inline uns get_u16(byte *p) { return get_u16_be(p); }
-static inline u32 get_u32(byte *p) { return get_u32_be(p); }
-static inline u64 get_u64(byte *p) { return get_u64_be(p); }
-static inline u64 get_u40(byte *p) { return get_u40_be(p); }
-static inline void put_u16(byte *p, uns x) { return put_u16_be(p, x); }
-static inline void put_u32(byte *p, u32 x) { return put_u32_be(p, x); }
-static inline void put_u64(byte *p, u64 x) { return put_u64_be(p, x); }
-static inline void put_u40(byte *p, u64 x) { return put_u40_be(p, x); }
+static inline uns get_u16(const void *p) { return get_u16_be(p); }
+static inline u32 get_u32(const void *p) { return get_u32_be(p); }
+static inline u64 get_u64(const void *p) { return get_u64_be(p); }
+static inline u64 get_u40(const void *p) { return get_u40_be(p); }
+static inline void put_u16(void *p, uns x) { return put_u16_be(p, x); }
+static inline void put_u32(void *p, u32 x) { return put_u32_be(p, x); }
+static inline void put_u64(void *p, u64 x) { return put_u64_be(p, x); }
+static inline void put_u40(void *p, u64 x) { return put_u40_be(p, x); }
#else
-static inline uns get_u16(byte *p) { return get_u16_le(p); }
-static inline u32 get_u32(byte *p) { return get_u32_le(p); }
-static inline u64 get_u64(byte *p) { return get_u64_le(p); }
-static inline u64 get_u40(byte *p) { return get_u40_le(p); }
-static inline void put_u16(byte *p, uns x) { return put_u16_le(p, x); }
-static inline void put_u32(byte *p, u32 x) { return put_u32_le(p, x); }
-static inline void put_u64(byte *p, u64 x) { return put_u64_le(p, x); }
-static inline void put_u40(byte *p, u64 x) { return put_u40_le(p, x); }
+static inline uns get_u16(const void *p) { return get_u16_le(p); }
+static inline u32 get_u32(const void *p) { return get_u32_le(p); }
+static inline u64 get_u64(const void *p) { return get_u64_le(p); }
+static inline u64 get_u40(const void *p) { return get_u40_le(p); }
+static inline void put_u16(void *p, uns x) { return put_u16_le(p, x); }
+static inline void put_u32(void *p, u32 x) { return put_u32_le(p, x); }
+static inline void put_u64(void *p, u64 x) { return put_u64_le(p, x); }
+static inline void put_u40(void *p, u64 x) { return put_u40_le(p, x); }
#endif
/* Just for completeness */
-static inline uns get_u8(byte *p) { return *p; }
-static inline void put_u8(byte *p, uns x) { *p = x; }
+static inline uns get_u8(const void *p) { return *(const byte *)p; }
+static inline void put_u8(void *p, uns x) { *(byte *)p = x; }
/* Backward compatibility macros */
-#define GET_U8(p) get_u8((byte*)(p))
-#define GET_U16(p) get_u16((byte*)(p))
-#define GET_U32(p) get_u32((byte*)(p))
-#define GET_U64(p) get_u64((byte*)(p))
-#define GET_U40(p) get_u40((byte*)(p))
-
-#define PUT_U8(p,x) put_u8((byte*)(p),x);
-#define PUT_U16(p,x) put_u16((byte*)(p),x)
-#define PUT_U32(p,x) put_u32((byte*)p,x)
-#define PUT_U64(p,x) put_u64((byte*)p,x)
-#define PUT_U40(p,x) put_u40((byte*)p,x)
+#define GET_U8(p) get_u8(p)
+#define GET_U16(p) get_u16(p)
+#define GET_U32(p) get_u32(p)
+#define GET_U64(p) get_u64(p)
+#define GET_U40(p) get_u40(p)
+
+#define PUT_U8(p,x) put_u8(p,x);
+#define PUT_U16(p,x) put_u16(p,x)
+#define PUT_U32(p,x) put_u32(p,x)
+#define PUT_U64(p,x) put_u64(p,x)
+#define PUT_U40(p,x) put_u40(p,x)
#endif
#include "lib/unicode.h"
uns
-utf8_strlen(byte *str)
+utf8_strlen(const byte *str)
{
uns len = 0;
while (*str)
}
uns
-utf8_strnlen(byte *str, uns n)
+utf8_strnlen(const byte *str, uns n)
{
uns len = 0;
- byte *end = str + n;
+ const byte *end = str + n;
while (str < end)
{
UTF8_SKIP(str);
}
uns
-utf8_check(byte *s)
+utf8_check(const byte *s)
{
#define UTF8_CHECK_NEXT if (unlikely((*s & 0xc0) != 0x80)) goto bad; s++
while (*s)
}
static inline byte *
-utf8_32_get(byte *p, uns *uu)
+utf8_32_get(const byte *p, uns *uu)
{
uns u = *p++;
if (u < 0x80)
else
goto bad;
*uu = u;
- return p;
+ return (byte *)p;
}
#define PUT_UTF8(p,u) p = utf8_put(p, u)
/* unicode-utf8.c */
-uns utf8_strlen(byte *str);
-uns utf8_strnlen(byte *str, uns n);
-uns utf8_check(byte *str);
+uns utf8_strlen(const byte *str);
+uns utf8_strnlen(const byte *str, uns n);
+uns utf8_check(const byte *str);
#endif
}
int
-url_deescape(byte *s, byte *d)
+url_deescape(const byte *s, byte *d)
{
byte *dstart = d;
byte *end = d + MAX_URL_SIZE - 10;
*d++ = *s++;
else if (Cspace(*s))
{
- byte *s0 = s;
+ const byte *s0 = s;
while (Cspace(*s))
s++;
if (!url_ignore_spaces || !(!*s || d == dstart))
}
int
-url_enescape(byte *s, byte *d)
+url_enescape(const byte *s, byte *d)
{
byte *end = d + MAX_URL_SIZE - 10;
unsigned int c;
}
int
-url_enescape_friendly(byte *src, byte *dest)
+url_enescape_friendly(const byte *src, byte *dest)
{
byte *end = dest + MAX_URL_SIZE - 10;
while (*src)
static int url_proto_path_flags[URL_PROTO_MAX] = URL_PATH_FLAGS;
uns
-identify_protocol(byte *p)
+identify_protocol(const byte *p)
{
uns i;
/* Pack a broken-down URL */
static byte *
-append(byte *d, byte *s, byte *e)
+append(byte *d, const byte *s, byte *e)
{
if (d)
while (*s)
/* Standard cookbook recipes */
int
-url_canon_split_rel(byte *u, byte *buf1, byte *buf2, struct url *url, struct url *base)
+url_canon_split_rel(const byte *u, byte *buf1, byte *buf2, struct url *url, struct url *base)
{
int err;
}
int
-url_auto_canonicalize_rel(byte *src, byte *dst, struct url *base)
+url_auto_canonicalize_rel(const byte *src, byte *dst, struct url *base)
{
byte buf1[MAX_URL_SIZE], buf2[MAX_URL_SIZE], buf3[MAX_URL_SIZE];
int err;
#endif
struct component {
- byte *start;
+ const byte *start;
int length;
u32 hash;
};
static inline u32
-hashf(byte *start, int length)
+hashf(const byte *start, int length)
{
u32 hf = length;
while (length-- > 0)
}
int
-url_has_repeated_component(byte *url)
+url_has_repeated_component(const byte *url)
{
struct component *comp;
uns comps, comp_len, rep_prefix;
- byte *c;
+ const byte *c;
uns i;
for (comps=0, c=url; c; comps++)
/* Remove/Introduce '%' escapes */
-int url_deescape(byte *s, byte *d);
-int url_enescape(byte *s, byte *d);
-int url_enescape_friendly(byte *src, byte *dest); // for cards.c only
+int url_deescape(const byte *s, byte *d);
+int url_enescape(const byte *s, byte *d);
+int url_enescape_friendly(const byte *src, byte *dest); // for cards.c only
/* URL splitting and normalization */
int url_normalize(struct url *u, struct url *b);
int url_canonicalize(struct url *u);
int url_pack(struct url *u, byte *d);
-int url_canon_split_rel(byte *url, byte *buf1, byte *buf2, struct url *u, struct url *base);
-int url_auto_canonicalize_rel(byte *src, byte *dst, struct url *base);
-uns identify_protocol(byte *p);
-int url_has_repeated_component(byte *url);
+int url_canon_split_rel(const byte *url, byte *buf1, byte *buf2, struct url *u, struct url *base);
+int url_auto_canonicalize_rel(const byte *src, byte *dst, struct url *base);
+uns identify_protocol(const byte *p);
+int url_has_repeated_component(const byte *url);
-static inline int url_canon_split(byte *url, byte *buf1, byte *buf2, struct url *u)
+static inline int url_canon_split(const byte *url, byte *buf1, byte *buf2, struct url *u)
{ return url_canon_split_rel(url, buf1, buf2, u, NULL); }
-static inline int url_auto_canonicalize(byte *src, byte *dst)
+static inline int url_auto_canonicalize(const byte *src, byte *dst)
{ return url_auto_canonicalize_rel(src, dst, NULL); }
/* Error codes */
}
struct wildpatt *
-wp_compile(byte *p, struct mempool *pool)
+wp_compile(const byte *p, struct mempool *pool)
{
struct wildpatt *w;
uns i;
}
int
-wp_match(struct wildpatt *w, byte *s)
+wp_match(struct wildpatt *w, const byte *s)
{
struct dfa_state *d;
}
int
-wp_min_size(byte *p)
+wp_min_size(const byte *p)
{
int s = 0;
struct wildpatt;
struct mempool;
-struct wildpatt *wp_compile(byte *, struct mempool *);
-int wp_match(struct wildpatt *, byte *);
-int wp_min_size(byte *);
+struct wildpatt *wp_compile(const byte *, struct mempool *);
+int wp_match(struct wildpatt *, const byte *);
+int wp_min_size(const byte *);