From 86897941a81703e1cbb14cbd3f4b3af1e3a1bcb8 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Thu, 21 Jun 2007 11:09:42 +0200 Subject: [PATCH] libucw: added more const qualifiers --- lib/adler32.c | 2 +- lib/conf-input.c | 16 ++++++++-------- lib/conf-internal.h | 2 +- lib/conf-intr.c | 4 ++-- lib/conf-section.c | 2 +- lib/fastbuf.c | 2 +- lib/fastbuf.h | 22 +++++++++++----------- lib/fb-atomic.c | 2 +- lib/fb-file.c | 6 +++--- lib/fb-mmap.c | 4 ++-- lib/ff-printf.c | 4 ++-- lib/getopt.h | 8 ++++---- lib/lfs.h | 2 +- lib/lizard-safe.c | 2 +- lib/lizard.c | 24 ++++++++++++------------ lib/lizard.h | 10 +++++----- lib/stkstring.h | 2 +- 17 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/adler32.c b/lib/adler32.c index 903cb1ce..cf3a652e 100644 --- a/lib/adler32.c +++ b/lib/adler32.c @@ -21,7 +21,7 @@ #define MOD(a) a %= BASE uns -update_adler32(uns adler, byte *buf, uns len) +update_adler32(uns adler, const byte *buf, uns len) { uns s1 = adler & 0xffff; uns s2 = (adler >> 16) & 0xffff; diff --git a/lib/conf-input.c b/lib/conf-input.c index 0272de21..d7e7766e 100644 --- a/lib/conf-input.c +++ b/lib/conf-input.c @@ -23,7 +23,7 @@ /* Text file parser */ -static byte *name_parse_fb; +static const byte *name_parse_fb; static struct fastbuf *parse_fb; static uns line_num; @@ -195,7 +195,7 @@ split_command(void) /* Parsing multiple files */ static byte * -parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth) +parse_fastbuf(const byte *name_fb, struct fastbuf *fb, uns depth) { byte *msg; name_parse_fb = name_fb; @@ -300,7 +300,7 @@ done_stack(void) } static int -load_file(byte *file) +load_file(const byte *file) { cf_init_stack(); struct fastbuf *fb = bopen_try(file, O_RDONLY, 1<<14); @@ -317,11 +317,11 @@ load_file(byte *file) } static int -load_string(byte *string) +load_string(const byte *string) { cf_init_stack(); struct fastbuf fb; - fbbuf_init_read(&fb, string, strlen(string), 0); + fbbuf_init_read(&fb, (byte *)string, strlen(string), 0); byte *msg = parse_fastbuf(NULL, &fb, 0); return !!msg || done_stack(); } @@ -329,7 +329,7 @@ load_string(byte *string) /* Safe loading and reloading */ int -cf_reload(byte *file) +cf_reload(const byte *file) { cf_journal_swap(); struct cf_journal_item *oldj = cf_journal_new_transaction(1); @@ -351,7 +351,7 @@ cf_reload(byte *file) } int -cf_load(byte *file) +cf_load(const byte *file) { struct cf_journal_item *oldj = cf_journal_new_transaction(1); int err = load_file(file); @@ -363,7 +363,7 @@ cf_load(byte *file) } int -cf_set(byte *string) +cf_set(const byte *string) { struct cf_journal_item *oldj = cf_journal_new_transaction(0); int err = load_string(string); diff --git a/lib/conf-internal.h b/lib/conf-internal.h index aeb44721..f0f70b8e 100644 --- a/lib/conf-internal.h +++ b/lib/conf-internal.h @@ -37,7 +37,7 @@ void cf_journal_delete(void); enum cf_commit_mode { CF_NO_COMMIT, CF_COMMIT, CF_COMMIT_ALL }; extern struct cf_section cf_sections; -struct cf_item *cf_find_subitem(struct cf_section *sec, byte *name); +struct cf_item *cf_find_subitem(struct cf_section *sec, const byte *name); int cf_commit_all(enum cf_commit_mode cm); void cf_add_dirty(struct cf_section *sec, void *ptr); diff --git a/lib/conf-intr.c b/lib/conf-intr.c index 9777e571..8bc06f82 100644 --- a/lib/conf-intr.c +++ b/lib/conf-intr.c @@ -483,7 +483,7 @@ closing_brace(struct item_stack *st, enum cf_operation op, int number, byte **pa } static struct cf_item * -find_item(struct cf_section *curr_sec, byte *name, byte **msg, void **ptr) +find_item(struct cf_section *curr_sec, const byte *name, byte **msg, void **ptr) { *msg = NULL; if (name[0] == '^') // absolute name instead of relative @@ -560,7 +560,7 @@ cf_interpret_line(byte *name, enum cf_operation op, int number, byte **pars) } byte * -cf_find_item(byte *name, struct cf_item *item) +cf_find_item(const byte *name, struct cf_item *item) { byte *msg; void *ptr = NULL; diff --git a/lib/conf-section.c b/lib/conf-section.c index bbd34164..e4a0712f 100644 --- a/lib/conf-section.c +++ b/lib/conf-section.c @@ -70,7 +70,7 @@ sort_dirty(void) struct cf_section cf_sections; // root section struct cf_item * -cf_find_subitem(struct cf_section *sec, byte *name) +cf_find_subitem(struct cf_section *sec, const byte *name) { struct cf_item *ci = sec->cfg; for (; ci->cls; ci++) diff --git a/lib/fastbuf.c b/lib/fastbuf.c index dcb8d20d..be7e9790 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -114,7 +114,7 @@ uns bread_slow(struct fastbuf *f, void *b, uns l, uns check) return total; } -void bwrite_slow(struct fastbuf *f, void *b, uns l) +void bwrite_slow(struct fastbuf *f, const void *b, uns l) { while (l) { diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 3a5a0e9d..7ec5ec6f 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -75,8 +75,8 @@ struct fastbuf { /* FastIO on standard files (specify buffer size 0 to enable mmaping) */ -struct fastbuf *bopen(byte *name, uns mode, uns buflen); -struct fastbuf *bopen_try(byte *name, uns mode, uns buflen); +struct fastbuf *bopen(const byte *name, uns mode, uns buflen); +struct fastbuf *bopen_try(const byte *name, uns mode, uns buflen); struct fastbuf *bopen_tmp(uns buflen); struct fastbuf *bfdopen(int fd, uns buflen); struct fastbuf *bfdopen_shared(int fd, uns buflen); @@ -92,7 +92,7 @@ struct fastbuf *fbmem_clone_read(struct fastbuf *); /* Create reading fastbuf */ /* FastIO on memory mapped files */ -struct fastbuf *bopen_mm(byte *name, uns mode); +struct fastbuf *bopen_mm(const byte *name, uns mode); /* FastI on file descriptors with limit */ @@ -124,7 +124,7 @@ struct fb_atomic { }; #define FB_ATOMIC(f) ((struct fb_atomic *)(f)->is_fastbuf) -struct fastbuf *fbatomic_open(byte *name, struct fastbuf *master, uns bufsize, int record_len); +struct fastbuf *fbatomic_open(const byte *name, struct fastbuf *master, uns bufsize, int record_len); void fbatomic_internal_write(struct fastbuf *b); static inline void @@ -217,8 +217,8 @@ static inline uns breadb(struct fastbuf *f, void *b, uns l) return bread_slow(f, b, l, 1); } -void bwrite_slow(struct fastbuf *f, void *b, uns l); -static inline void bwrite(struct fastbuf *f, void *b, uns l) +void bwrite_slow(struct fastbuf *f, const void *b, uns l); +static inline void bwrite(struct fastbuf *f, const void *b, uns l) { if (bavailw(f) >= l) { @@ -263,19 +263,19 @@ void bgets_stk_step(struct bgets_stk_struct *s); #define bgets_stk(fb) ({ struct bgets_stk_struct _s; _s.f = (fb); for (bgets_stk_init(&_s); _s.cur_len; _s.cur_buf = alloca(_s.cur_len), bgets_stk_step(&_s)); _s.cur_buf; }) static inline void -bputs(struct fastbuf *f, byte *b) +bputs(struct fastbuf *f, const byte *b) { bwrite(f, b, strlen(b)); } static inline void -bputs0(struct fastbuf *f, byte *b) +bputs0(struct fastbuf *f, const byte *b) { bwrite(f, b, strlen(b)+1); } static inline void -bputsn(struct fastbuf *f, byte *b) +bputsn(struct fastbuf *f, const byte *b) { bputs(f, b); bputc(f, '\n'); @@ -351,7 +351,7 @@ bdirect_write_commit(struct fastbuf *f, byte *pos) /* Formatted output */ -int bprintf(struct fastbuf *b, char *msg, ...) FORMAT_CHECK(printf,2,3); -int vbprintf(struct fastbuf *b, char *msg, va_list args); +int bprintf(struct fastbuf *b, const char *msg, ...) FORMAT_CHECK(printf,2,3); +int vbprintf(struct fastbuf *b, const char *msg, va_list args); #endif diff --git a/lib/fb-atomic.c b/lib/fb-atomic.c index 73dd8b13..c578a951 100644 --- a/lib/fb-atomic.c +++ b/lib/fb-atomic.c @@ -103,7 +103,7 @@ fbatomic_close(struct fastbuf *f) } struct fastbuf * -fbatomic_open(byte *name, struct fastbuf *master, uns bufsize, int record_len) +fbatomic_open(const byte *name, struct fastbuf *master, uns bufsize, int record_len) { struct fb_atomic *F = xmalloc_zero(sizeof(*F)); struct fastbuf *f = &F->fb; diff --git a/lib/fb-file.c b/lib/fb-file.c index a7290cbf..637446a0 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -92,7 +92,7 @@ bfd_config(struct fastbuf *f, uns item, int value) } static struct fastbuf * -bfdopen_internal(int fd, uns buflen, byte *name) +bfdopen_internal(int fd, uns buflen, const byte *name) { int namelen = strlen(name) + 1; struct fb_file *F = xmalloc(sizeof(struct fb_file) + buflen + namelen); @@ -115,7 +115,7 @@ bfdopen_internal(int fd, uns buflen, byte *name) } struct fastbuf * -bopen_try(byte *name, uns mode, uns buflen) +bopen_try(const byte *name, uns mode, uns buflen) { int fd = sh_open(name, mode, 0666); if (fd < 0) @@ -127,7 +127,7 @@ bopen_try(byte *name, uns mode, uns buflen) } struct fastbuf * -bopen(byte *name, uns mode, uns buflen) +bopen(const byte *name, uns mode, uns buflen) { if (!buflen) return bopen_mm(name, mode); diff --git a/lib/fb-mmap.c b/lib/fb-mmap.c index 41e65832..948dcf58 100644 --- a/lib/fb-mmap.c +++ b/lib/fb-mmap.c @@ -166,7 +166,7 @@ bfmm_config(struct fastbuf *f, uns item, int value) } static struct fastbuf * -bfmmopen_internal(int fd, byte *name, uns mode) +bfmmopen_internal(int fd, const byte *name, uns mode) { int namelen = strlen(name) + 1; struct fb_mmap *F = xmalloc(sizeof(struct fb_mmap) + namelen); @@ -190,7 +190,7 @@ bfmmopen_internal(int fd, byte *name, uns mode) } struct fastbuf * -bopen_mm(byte *name, uns mode) +bopen_mm(const byte *name, uns mode) { int fd; diff --git a/lib/ff-printf.c b/lib/ff-printf.c index 8825a288..0493092e 100644 --- a/lib/ff-printf.c +++ b/lib/ff-printf.c @@ -14,7 +14,7 @@ #include int -vbprintf(struct fastbuf *b, char *msg, va_list args) +vbprintf(struct fastbuf *b, const char *msg, va_list args) { byte *buf; int len, r; @@ -58,7 +58,7 @@ vbprintf(struct fastbuf *b, char *msg, va_list args) } int -bprintf(struct fastbuf *b, char *msg, ...) +bprintf(struct fastbuf *b, const char *msg, ...) { va_list args; int res; diff --git a/lib/getopt.h b/lib/getopt.h index 6f29af8a..85321ee9 100644 --- a/lib/getopt.h +++ b/lib/getopt.h @@ -22,9 +22,9 @@ void reset_getopt(void); /* Safe loading and reloading of configuration files: conf-input.c */ extern byte *cf_def_file; /* DEFAULT_CONFIG; NULL if already loaded */ -int cf_reload(byte *file); -int cf_load(byte *file); -int cf_set(byte *string); +int cf_reload(const byte *file); +int cf_load(const byte *file); +int cf_set(const byte *string); /* Direct access to configuration items: conf-intr.c */ @@ -40,7 +40,7 @@ enum cf_operation { CF_OPERATIONS }; #undef T struct cf_item; -byte *cf_find_item(byte *name, struct cf_item *item); +byte *cf_find_item(const byte *name, struct cf_item *item); byte *cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars); /* Debug dumping: conf-dump.c */ diff --git a/lib/lfs.h b/lib/lfs.h index 3896c0e6..ec588e65 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(byte *name) +sh_file_size(const byte *name) { int fd = sh_open(name, O_RDONLY); if (fd < 0) diff --git a/lib/lizard-safe.c b/lib/lizard-safe.c index 0473e34a..3b927831 100644 --- a/lib/lizard-safe.c +++ b/lib/lizard-safe.c @@ -69,7 +69,7 @@ sigsegv_handler(int signal UNUSED) } byte * -lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length) +lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length) /* Decompresses in into buf, sets *ptr to the data, and returns the * uncompressed length. If an error has occured, -1 is returned and errno is * set. The buffer buf is automatically reallocated. SIGSEGV is caught in diff --git a/lib/lizard.c b/lib/lizard.c index e5035e05..1da67ccd 100644 --- a/lib/lizard.c +++ b/lib/lizard.c @@ -28,25 +28,25 @@ struct hash_record { #define CHAIN_GOOD_MATCH 32 // we already have a good match => end static inline uns -hashf(byte *string) +hashf(const byte *string) /* 0..HASH_SIZE-1 */ { return string[0] ^ (string[1]<<3) ^ (string[2]<<6); } static inline byte * -locate_string(byte *string, int record_id, int head) +locate_string(const byte *string, int record_id, int head) /* The strings are recorded into the hash-table regularly, hence there is no * need to store the pointer there. */ { string += record_id - head; if (record_id >= head) string -= HASH_RECORDS-1; - return string; + return (byte *)string; } static inline uns -find_match(uns record_id, struct hash_record *hash_rec, byte *string, byte *string_end, byte **best_ptr, uns head) +find_match(uns record_id, struct hash_record *hash_rec, const byte *string, const byte *string_end, byte **best_ptr, uns head) /* hash_tab[hash] == record_id points to the head of the double-linked * link-list of strings with the same hash. The records are statically * stored in circular array hash_rec (with the 1st entry unused), and the @@ -68,7 +68,7 @@ find_match(uns record_id, struct hash_record *hash_rec, byte *string, byte *stri if (*cmp++ == string[4] && *cmp++ == string[5] && *cmp++ == string[6] && *cmp++ == string[7]) { - byte *str = string + 8; + const byte *str = string + 8; while (str <= string_end && *cmp++ == *str++); } } @@ -128,7 +128,7 @@ dump_unary_value(byte *out, uns l) } static byte * -flush_copy_command(uns bof, byte *out, byte *start, uns len) +flush_copy_command(uns bof, byte *out, const byte *start, uns len) { if (bof && len <= 238) *out++ = len + 17; @@ -161,16 +161,16 @@ flush_copy_command(uns bof, byte *out, byte *start, uns len) } int -lizard_compress(byte *in, uns in_len, byte *out) +lizard_compress(const byte *in, uns in_len, byte *out) /* Requires out being allocated for at least in_len * LIZARD_MAX_MULTIPLY + * LIZARD_MAX_ADD. There must be at least LIZARD_NEEDS_CHARS characters * allocated after in. Returns the actual compressed length. */ { hash_ptr_t hash_tab[HASH_SIZE]; struct hash_record hash_rec[HASH_RECORDS]; - byte *in_end = in + in_len; + const byte *in_end = in + in_len; byte *out_start = out; - byte *copy_start = in; + const byte *copy_start = in; uns head = 1; /* 0 in unused */ uns to_delete = 0, bof = 1; bzero(hash_tab, sizeof(hash_tab)); /* init the hash-table */ @@ -280,18 +280,18 @@ dump_2sequence: } static inline byte * -read_unary_value(byte *in, uns *val) +read_unary_value(const byte *in, uns *val) { uns l = 0; while (!*in++) l += 255; l += in[-1]; *val = l; - return in; + return (byte *)in; } int -lizard_decompress(byte *in, byte *out) +lizard_decompress(const byte *in, byte *out) /* Requires out being allocated for the decompressed length must be known * beforehand. It is desirable to lock the following memory page for * read-only access to prevent buffer overflow. Returns the actual diff --git a/lib/lizard.h b/lib/lizard.h index aa616515..616d17b0 100644 --- a/lib/lizard.h +++ b/lib/lizard.h @@ -27,21 +27,21 @@ */ /* lizard.c */ -int lizard_compress(byte *in, uns in_len, byte *out); -int lizard_decompress(byte *in, byte *out); +int lizard_compress(const byte *in, uns in_len, byte *out); +int lizard_decompress(const byte *in, byte *out); /* lizard-safe.c */ struct lizard_buffer; struct lizard_buffer *lizard_alloc(void); void lizard_free(struct lizard_buffer *buf); -byte *lizard_decompress_safe(byte *in, struct lizard_buffer *buf, uns expected_length); +byte *lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length); /* adler32.c */ -uns update_adler32(uns adler, byte *ptr, uns len); +uns update_adler32(uns adler, const byte *ptr, uns len); static inline uns -adler32(byte *buf, uns len) +adler32(const byte *buf, uns len) { return update_adler32(1, buf, len); } diff --git a/lib/stkstring.h b/lib/stkstring.h index bd7e21ef..e5cdc260 100644 --- a/lib/stkstring.h +++ b/lib/stkstring.h @@ -15,7 +15,7 @@ #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_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_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; }) -- 2.39.2