at places where it is straight-forward.
#include <errno.h>
int
-format_exit_status(byte *msg, int stat)
+format_exit_status(char *msg, int stat)
{
if (stat < 0)
sprintf(msg, "failed to fork (err=%d)", errno);
#define HAVE_PREAD
static inline sh_off_t
-sh_file_size(const byte *name)
+sh_file_size(const char *name)
{
int fd = sh_open(name, O_RDONLY);
if (fd < 0)
/* wordsplit.c */
-int sepsplit(byte *str, byte sep, byte **rec, uns max);
+int sepsplit(byte *str, uns sep, byte **rec, uns max);
int wordsplit(byte *str, byte **rec, uns max);
/* pat(i)match.c: Matching of shell patterns */
/* md5hex.c */
-void md5_to_hex(const byte *s, byte *d);
-void hex_to_md5(const byte *s, byte *d);
+void md5_to_hex(const byte *s, char *d);
+void hex_to_md5(const char *s, byte *d);
#define MD5_SIZE 16
#define MD5_HEX_SIZE 33
typedef struct regex regex;
-regex *rx_compile(const byte *r, int icase);
+regex *rx_compile(const char *r, int icase);
void rx_free(regex *r);
-int rx_match(regex *r, const byte *s);
-int rx_subst(regex *r, const byte *by, const byte *src, byte *dest, uns destlen);
+int rx_match(regex *r, const char *s);
+int rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen);
/* random.c */
/* mmap.c */
-void *mmap_file(const byte *name, unsigned *len, int writeable);
+void *mmap_file(const char *name, unsigned *len, int writeable);
void munmap_file(void *start, unsigned len);
/* proctitle.c */
/* exitstatus.c */
#define EXIT_STATUS_MSG_SIZE 32
-int format_exit_status(byte *msg, int stat);
+int format_exit_status(char *msg, int stat);
/* runcmd.c */
-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);
+int run_command(const char *cmd, ...);
+void NONRET exec_command(const char *cmd, ...);
+void echo_command(char *buf, int size, const char *cmd, ...);
+int run_command_v(const char *cmd, va_list args);
+void NONRET exec_command_v(const char *cmd, va_list args);
+void echo_command_v(char *buf, int size, const char *cmd, va_list args);
/* carefulio.c */
/* sync.c */
-void sync_dir(const byte *name);
+void sync_dir(const char *name);
/* sighandler.c */
/* string.c */
-byte *str_unesc(byte *dest, const byte *src);
-byte *str_format_flags(byte *dest, const byte *fmt, uns flags);
+char *str_unesc(char *dest, const char *src);
+char *str_format_flags(char *dest, const char *fmt, uns flags);
/* bigalloc.c */
cnode n;
int pid; /* Process id (0=not running) */
int status; /* Exit status (-1=fork failed) */
- byte status_msg[EXIT_STATUS_MSG_SIZE];
+ char status_msg[EXIT_STATUS_MSG_SIZE];
void (*handler)(struct main_process *mp); /* [*] Called when the process exits; process_del done automatically */
void *data; /* [*] For use by the handler */
};
#include <stdio.h>
void
-md5_to_hex(const byte *s, byte *d)
+md5_to_hex(const byte *s, char *d)
{
int i;
for(i=0; i<MD5_SIZE; i++)
}
void
-hex_to_md5(const byte *s, byte *d)
+hex_to_md5(const char *s, byte *d)
{
uns i, j;
for(i=0; i<MD5_SIZE; i++)
#include <sys/mman.h>
void *
-mmap_file(const byte *name, unsigned *len, int writeable)
+mmap_file(const char *name, unsigned *len, int writeable)
{
int fd = open(name, writeable ? O_RDWR : O_RDONLY);
struct stat st;
#endif
struct partmap *
-partmap_open(byte *name, int writeable)
+partmap_open(char *name, int writeable)
{
struct partmap *p = xmalloc_zero(sizeof(struct partmap));
int writeable;
};
-struct partmap *partmap_open(byte *name, int writeable);
+struct partmap *partmap_open(char *name, int writeable);
void partmap_close(struct partmap *p);
sh_off_t partmap_size(struct partmap *p);
void partmap_load(struct partmap *p, sh_off_t start, uns size);
static inline void prof_start(prof_t *c) { prof_switch(NULL, c); }
static inline void prof_stop(prof_t *c) { prof_switch(c, NULL); }
#endif
-#define PROF_STR(C) ({ static byte _x[PROF_STR_SIZE]; prof_format(_x, &(C)); _x; })
+#define PROF_STR(C) ({ static char _x[PROF_STR_SIZE]; prof_format(_x, &(C)); _x; })
#else
int fd;
byte *mmap_data;
uns file_size;
- byte *file_name;
+ char *file_name;
uns locked;
};
#define first_free_block entry_table[0].first_data_block
#define num_free_blocks entry_table[0].data_len
-static inline byte *
+static inline char *
format_key(qache_key_t *key)
{
- static byte keybuf[2*sizeof(qache_key_t)+1];
+ static char keybuf[2*sizeof(qache_key_t)+1];
for (uns i=0; i<sizeof(qache_key_t); i++)
sprintf(keybuf+2*i, "%02x", (*key)[i]);
return keybuf;
ET_HASH = 4
};
-static byte *
+static char *
audit_entries(struct qache *q, byte *entrymap)
{
uns i, j;
BT_ALLOC = 2
};
-static byte *
+static char *
audit_blocks(struct qache *q, byte *entrymap, byte *blockmap)
{
uns i, j;
return NULL;
}
-static byte *
+static char *
do_audit(struct qache *q)
{
byte *entry_map = xmalloc_zero(q->hdr->max_entries);
return 0;
struct stat st;
- byte *err = "stat failed";
+ char *err = "stat failed";
if (fstat(q->fd, &st) < 0)
goto close_and_fail;
void
qache_audit(struct qache *q)
{
- byte *err;
+ char *err;
qache_lock(q);
if (err = do_audit(q))
die("Cache %s: %s", q->file_name, err);
#define _UCW_QACHE_H
struct qache_params {
- byte *file_name;
+ char *file_name;
uns block_size; /* Cache block size (a power of two) */
uns cache_size; /* Size of the whole cache */
uns max_entries; /* Maximum number of cached entries */
};
regex *
-rx_compile(const byte *p, int icase)
+rx_compile(const char *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
int err = regcomp(&r->rx, p, REG_EXTENDED | (icase ? REG_ICASE : 0));
if (err)
{
- byte msg[256];
+ char msg[256];
regerror(err, &r->rx, msg, sizeof(msg)-1);
/* regfree(&r->rx) not needed */
die("Error parsing regular expression `%s': %s", p, msg);
}
int
-rx_match(regex *r, const byte *s)
+rx_match(regex *r, const char *s)
{
int err = regexec(&r->rx, s, 10, r->matches, 0);
if (!err)
}
int
-rx_subst(regex *r, const byte *by, const byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, const char *by, const char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j <= r->rx.re_nsub && r->matches[j].rm_so >= 0)
{
- const byte *s = src + r->matches[j].rm_so;
+ const char *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;
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(char *p, int icase)
{
const char *err;
int errpos, match_array_size, eno;
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, char *s)
{
int len = str_len(s);
int err = pcre_exec(r->rx, r->extra, s, len, 0, 0, r->matches, r->match_array_size);
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, char *by, char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j < r->real_matches && r->matches[2*j] >= 0)
{
- byte *s = src + r->matches[2*j];
+ char *s = src + r->matches[2*j];
uns i = r->matches[2*j+1] - r->matches[2*j];
if (dest + i >= end)
return -1;
};
regex *
-rx_compile(byte *p, int icase)
+rx_compile(char *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
const char *msg;
}
int
-rx_match(regex *r, byte *s)
+rx_match(regex *r, char *s)
{
int len = strlen(s);
}
int
-rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen)
+rx_subst(regex *r, char *by, char *src, char *dest, uns destlen)
{
- byte *end = dest + destlen - 1;
+ char *end = dest + destlen - 1;
if (!rx_match(r, src))
return 0;
uns j = *by++ - '0';
if (j < r->regs.num_regs)
{
- byte *s = src + r->regs.start[j];
+ char *s = src + r->regs.start[j];
uns i = r->regs.end[j] - r->regs.start[j];
if (r->regs.start[j] > r->len_cache || r->regs.end[j] > r->len_cache)
return -1;
int main(int argc, char **argv)
{
regex *r;
- byte buf1[4096], buf2[4096];
+ char buf1[4096], buf2[4096];
int opt_i = 0;
if (!strcmp(argv[1], "-i"))
#include <sys/wait.h>
void NONRET
-exec_command_v(const byte *cmd, va_list args)
+exec_command_v(const char *cmd, va_list args)
{
va_list cargs;
va_copy(cargs, args);
int cnt = 2;
- byte *arg;
- while (arg = va_arg(cargs, byte *))
+ char *arg;
+ while (arg = va_arg(cargs, char *))
cnt++;
va_end(cargs);
- char **argv = alloca(sizeof(byte *) * cnt);
+ char **argv = alloca(sizeof(char *) * cnt);
argv[0] = (char *)cmd;
cnt = 1;
va_copy(cargs, args);
- while (arg = va_arg(cargs, byte *))
+ while (arg = va_arg(cargs, char *))
argv[cnt++] = arg;
va_end(cargs);
argv[cnt] = NULL;
execv(cmd, argv);
- byte echo[256];
+ char echo[256];
echo_command_v(echo, sizeof(echo), cmd, args);
msg(L_ERROR, "Cannot execute %s: %m", echo);
exit(255);
}
int
-run_command_v(const byte *cmd, va_list args)
+run_command_v(const char *cmd, va_list args)
{
pid_t p = fork();
if (p < 0)
else
{
int stat;
- byte status_msg[EXIT_STATUS_MSG_SIZE];
+ char status_msg[EXIT_STATUS_MSG_SIZE];
p = waitpid(p, &stat, 0);
if (p < 0)
die("waitpid() failed: %m");
if (format_exit_status(status_msg, stat))
{
- byte echo[256];
+ char echo[256];
echo_command_v(echo, sizeof(echo), cmd, args);
msg(L_ERROR, "`%s' failed: %s", echo, status_msg);
return 0;
}
void
-echo_command_v(byte *buf, int size, const byte *cmd, va_list args)
+echo_command_v(char *buf, int size, const char *cmd, va_list args)
{
- byte *limit = buf + size - 4;
- byte *p = buf;
- const byte *arg = cmd;
+ char *limit = buf + size - 4;
+ char *p = buf;
+ const char *arg = cmd;
do
{
int l = strlen(arg);
memcpy(p, arg, l);
p += l;
}
- while (arg = va_arg(args, byte *));
+ while (arg = va_arg(args, char *));
*p = 0;
}
int
-run_command(const byte *cmd, ...)
+run_command(const char *cmd, ...)
{
va_list args;
va_start(args, cmd);
}
void NONRET
-exec_command(const byte *cmd, ...)
+exec_command(const char *cmd, ...)
{
va_list args;
va_start(args, cmd);
}
void
-echo_command(byte *buf, int len, const byte *cmd, ...)
+echo_command(char *buf, int len, const char *cmd, ...)
{
va_list args;
va_start(args, cmd);
int main(void)
{
- byte msg[1024];
+ char msg[1024];
echo_command(msg, sizeof(msg), "/bin/echo", "datel", "strakapoud", NULL);
log(L_INFO, "Running <%s>", msg);
run_command("/bin/echo", "datel", "strakapoud", NULL);
sem_alloc(void)
{
static uns cnt = 0;
- byte buf[20];
+ char buf[20];
sprintf(buf, "tmp/sem-%d-%d", getpid(), cnt++);
sem_t *sem = sem_open(buf, O_CREAT, 0777, 0);
ASSERT(sem != (sem_t*) SEM_FAILED);
#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) ({ const byte *_s=(s); byte *_d=alloca(strlen(_s)+1); str_unesc(_d, _s); _d; })
+#define stk_hexdump(s,n) ({ uns _n=(n); char *_x=alloca(3*_n+1); stk_hexdump_internal(_x,(char*)(s),_n); _x; })
+#define stk_str_unesc(s) ({ const char *_s=(s); char *_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);
/* Expands C99-like escape sequences.
* It is safe to use the same buffer for both input and output. */
-byte *
-str_unesc(byte *d, const byte *s)
+char *
+str_unesc(char *d, const char *s)
{
while (*s)
{
*d++ = v;
else
DBG("hex escape sequence out of range");
- s = (byte *)p;
+ s = (char *)p;
}
break;
default:
return d;
}
-byte *
-str_format_flags(byte *dest, const byte *fmt, uns flags)
+char *
+str_format_flags(char *dest, const char *fmt, uns flags)
{
- byte *start = dest;
+ char *start = dest;
for (uns i=0; fmt[i]; i++)
{
if (flags & (1 << i))
#include <unistd.h>
void
-sync_dir(const byte *name)
+sync_dir(const char *name)
{
int fd = open(name, O_RDONLY
#ifdef CONFIG_LINUX
#include <string.h>
int
-sepsplit(byte *str, byte sep, byte **rec, uns max)
+sepsplit(byte *str, uns sep, byte **rec, uns max)
{
uns cnt = 0;
while (1)