From 9e39fe7af3726bf00324c7d0e758908b2ebe9e77 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 22 Jun 2007 11:31:26 +0200 Subject: [PATCH] Use `char *' instead of `byte *' for strings at places where it is straight-forward. --- lib/exitstatus.c | 2 +- lib/lfs.h | 2 +- lib/lib.h | 34 +++++++++++++++++----------------- lib/mainloop.h | 2 +- lib/md5hex.c | 4 ++-- lib/mmap.c | 2 +- lib/partmap.c | 2 +- lib/partmap.h | 2 +- lib/profile.h | 2 +- lib/qache.c | 16 ++++++++-------- lib/qache.h | 2 +- lib/regex.c | 34 +++++++++++++++++----------------- lib/runcmd.c | 36 ++++++++++++++++++------------------ lib/semaphore.h | 2 +- lib/stkstring.h | 4 ++-- lib/string.c | 12 ++++++------ lib/sync.c | 2 +- lib/wordsplit.c | 2 +- 18 files changed, 81 insertions(+), 81 deletions(-) diff --git a/lib/exitstatus.c b/lib/exitstatus.c index 4dce53d0..1095c7ff 100644 --- a/lib/exitstatus.c +++ b/lib/exitstatus.c @@ -14,7 +14,7 @@ #include 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); diff --git a/lib/lfs.h b/lib/lfs.h index ec588e65..ede41268 100644 --- a/lib/lfs.h +++ b/lib/lfs.h @@ -50,7 +50,7 @@ typedef struct stat sh_stat_t; #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) diff --git a/lib/lib.h b/lib/lib.h index e7916a11..6e74b6f5 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -164,7 +164,7 @@ int match_ct_patt(const char *, const char *); /* 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 */ @@ -174,8 +174,8 @@ int match_pattern_nocase(const char *patt, const char *str); /* 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 @@ -202,10 +202,10 @@ void get_last_timeval(struct timeval *tv); 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 */ @@ -216,7 +216,7 @@ u64 random_max_u64(u64 max); /* 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 */ @@ -232,16 +232,16 @@ void randomkey(byte *buf, uns size); /* 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 */ @@ -250,7 +250,7 @@ int careful_write(int fd, const void *buf, int len); /* sync.c */ -void sync_dir(const byte *name); +void sync_dir(const char *name); /* sighandler.c */ @@ -262,8 +262,8 @@ sh_sighandler_t set_signal_handler(int signum, sh_sighandler_t new); /* 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 */ diff --git a/lib/mainloop.h b/lib/mainloop.h index f321c2b5..aca8914f 100644 --- a/lib/mainloop.h +++ b/lib/mainloop.h @@ -91,7 +91,7 @@ struct main_process { 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 */ }; diff --git a/lib/md5hex.c b/lib/md5hex.c index 5f2e8ebb..93987b00 100644 --- a/lib/md5hex.c +++ b/lib/md5hex.c @@ -13,7 +13,7 @@ #include void -md5_to_hex(const byte *s, byte *d) +md5_to_hex(const byte *s, char *d) { int i; for(i=0; i 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; diff --git a/lib/partmap.c b/lib/partmap.c index baaef9c2..2b70f1d9 100644 --- a/lib/partmap.c +++ b/lib/partmap.c @@ -30,7 +30,7 @@ #endif struct partmap * -partmap_open(byte *name, int writeable) +partmap_open(char *name, int writeable) { struct partmap *p = xmalloc_zero(sizeof(struct partmap)); diff --git a/lib/partmap.h b/lib/partmap.h index 1be70ded..985b3626 100644 --- a/lib/partmap.h +++ b/lib/partmap.h @@ -19,7 +19,7 @@ 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); diff --git a/lib/profile.h b/lib/profile.h index c3c29df1..3704b449 100644 --- a/lib/profile.h +++ b/lib/profile.h @@ -123,7 +123,7 @@ typedef struct prof_ktsc prof_t; 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 diff --git a/lib/qache.c b/lib/qache.c index 854a12df..91536bf7 100644 --- a/lib/qache.c +++ b/lib/qache.c @@ -60,7 +60,7 @@ struct qache { int fd; byte *mmap_data; uns file_size; - byte *file_name; + char *file_name; uns locked; }; @@ -68,10 +68,10 @@ struct qache { #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; ihdr->max_entries); @@ -255,7 +255,7 @@ qache_open_existing(struct qache *q, struct qache_params *par) return 0; struct stat st; - byte *err = "stat failed"; + char *err = "stat failed"; if (fstat(q->fd, &st) < 0) goto close_and_fail; @@ -727,7 +727,7 @@ qache_debug(struct qache *q) 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); diff --git a/lib/qache.h b/lib/qache.h index 48a9e31c..5c242a45 100644 --- a/lib/qache.h +++ b/lib/qache.h @@ -8,7 +8,7 @@ #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 */ diff --git a/lib/regex.c b/lib/regex.c index adff133e..3baf297e 100644 --- a/lib/regex.c +++ b/lib/regex.c @@ -31,14 +31,14 @@ struct regex { }; 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); @@ -54,7 +54,7 @@ rx_free(regex *r) } 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) @@ -71,9 +71,9 @@ rx_match(regex *r, const byte *s) } 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; @@ -88,7 +88,7 @@ rx_subst(regex *r, const byte *by, const byte *src, byte *dest, uns destlen) 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; @@ -122,7 +122,7 @@ struct regex { }; regex * -rx_compile(byte *p, int icase) +rx_compile(char *p, int icase) { const char *err; int errpos, match_array_size, eno; @@ -152,7 +152,7 @@ rx_free(regex *r) } 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); @@ -171,9 +171,9 @@ rx_match(regex *r, byte *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; @@ -188,7 +188,7 @@ rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen) 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; @@ -227,7 +227,7 @@ struct regex { }; regex * -rx_compile(byte *p, int icase) +rx_compile(char *p, int icase) { regex *r = xmalloc_zero(sizeof(regex)); const char *msg; @@ -261,7 +261,7 @@ rx_free(regex *r) } int -rx_match(regex *r, byte *s) +rx_match(regex *r, char *s) { int len = strlen(s); @@ -274,9 +274,9 @@ rx_match(regex *r, byte *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; @@ -291,7 +291,7 @@ rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen) 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; @@ -319,7 +319,7 @@ rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen) 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")) diff --git a/lib/runcmd.c b/lib/runcmd.c index c18dcab1..0204e1db 100644 --- a/lib/runcmd.c +++ b/lib/runcmd.c @@ -16,32 +16,32 @@ #include 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) @@ -54,13 +54,13 @@ run_command_v(const byte *cmd, va_list args) 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; @@ -70,11 +70,11 @@ run_command_v(const byte *cmd, va_list args) } 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); @@ -89,12 +89,12 @@ echo_command_v(byte *buf, int size, const byte *cmd, va_list args) 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); @@ -104,7 +104,7 @@ run_command(const byte *cmd, ...) } void NONRET -exec_command(const byte *cmd, ...) +exec_command(const char *cmd, ...) { va_list args; va_start(args, cmd); @@ -112,7 +112,7 @@ exec_command(const byte *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); @@ -124,7 +124,7 @@ echo_command(byte *buf, int len, const byte *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); diff --git a/lib/semaphore.h b/lib/semaphore.h index d33280bd..fa2e0ee4 100644 --- a/lib/semaphore.h +++ b/lib/semaphore.h @@ -24,7 +24,7 @@ static inline sem_t * 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); diff --git a/lib/stkstring.h b/lib/stkstring.h index e5cdc260..49431c18 100644 --- a/lib/stkstring.h +++ b/lib/stkstring.h @@ -20,8 +20,8 @@ #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); diff --git a/lib/string.c b/lib/string.c index 3bc231a6..602a7d73 100644 --- a/lib/string.c +++ b/lib/string.c @@ -16,8 +16,8 @@ /* 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) { @@ -49,7 +49,7 @@ str_unesc(byte *d, const byte *s) *d++ = v; else DBG("hex escape sequence out of range"); - s = (byte *)p; + s = (char *)p; } break; default: @@ -74,10 +74,10 @@ str_unesc(byte *d, const byte *s) 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)) diff --git a/lib/sync.c b/lib/sync.c index a4c9b05a..6341415a 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -10,7 +10,7 @@ #include void -sync_dir(const byte *name) +sync_dir(const char *name) { int fd = open(name, O_RDONLY #ifdef CONFIG_LINUX diff --git a/lib/wordsplit.c b/lib/wordsplit.c index d13f2108..70984ab5 100644 --- a/lib/wordsplit.c +++ b/lib/wordsplit.c @@ -14,7 +14,7 @@ #include int -sepsplit(byte *str, byte sep, byte **rec, uns max) +sepsplit(byte *str, uns sep, byte **rec, uns max) { uns cnt = 0; while (1) -- 2.39.2