]> mj.ucw.cz Git - libucw.git/commitdiff
libucw: added more const qualifiers
authorPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 21 Jun 2007 09:09:42 +0000 (11:09 +0200)
committerPavel Charvat <pavel.charvat@netcentrum.cz>
Thu, 21 Jun 2007 09:09:42 +0000 (11:09 +0200)
17 files changed:
lib/adler32.c
lib/conf-input.c
lib/conf-internal.h
lib/conf-intr.c
lib/conf-section.c
lib/fastbuf.c
lib/fastbuf.h
lib/fb-atomic.c
lib/fb-file.c
lib/fb-mmap.c
lib/ff-printf.c
lib/getopt.h
lib/lfs.h
lib/lizard-safe.c
lib/lizard.c
lib/lizard.h
lib/stkstring.h

index 903cb1cee189d78a97821f7a0e227d7167896754..cf3a652e9391a25c8aafcfbf576af620af4d4733 100644 (file)
@@ -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;
index 0272de21eb27722c68a1704cdb862d80640136c3..d7e7766e971e390e408422f7848abb768e78abe8 100644 (file)
@@ -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);
index aeb44721702d860766c55f94de4fa68f7627b708..f0f70b8e232741d646f1b283d066f2791b18a877 100644 (file)
@@ -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);
 
index 9777e5711a426f71e409dd6a4369312e041ac2a7..8bc06f82323fc6280842900c04c356f066f98e78 100644 (file)
@@ -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;
index bbd3416426ef5ddc643928cfb739cd07bf34102f..e4a0712f0bbb627e0d91cf61b93ddb5b22abffd7 100644 (file)
@@ -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++)
index dcb8d20dc0fe305b1229b2418ee89390bb4ae0ad..be7e979015e0f797021cd9eb19c53ea68188f6de 100644 (file)
@@ -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)
     {
index 3a5a0e9dce90fd57c2c8fd8151d85005c8c490fe..7ec5ec6f2ca993fd91fe6d1951260950ddee3460 100644 (file)
@@ -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
index 73dd8b13ff826e6686fc5ae901e44761e479c1e9..c578a951bb118c17fb8b21d161c0905574ece012 100644 (file)
@@ -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;
index a7290cbf8688f9de261a38c4e50dbb9584eee91e..637446a02b065925d56484ce59c82e6785c36886 100644 (file)
@@ -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);
index 41e65832653c8c16180920d78172bc6221428e63..948dcf5850bc44267f9d9f7fc76474de4890baae 100644 (file)
@@ -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;
 
index 8825a2880437dff93a19e29b5e947d68b294a64b..0493092e6a0f4f57c482dee64f2f2abc0f43eb4d 100644 (file)
@@ -14,7 +14,7 @@
 #include <alloca.h>
 
 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;
index 6f29af8a182607990bf41d59275a074d7fdcf2b4..85321ee901a667b4e6a52f008e6befb35d566348 100644 (file)
@@ -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 */
index 3896c0e61d2655d4b1b0224f54a1593ad04495dd..ec588e65352d8760c80c8aa294e1363425ee9006 100644 (file)
--- 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)
index 0473e34ae7270215267adb6b59e342eb43140485..3b927831a71767c1b802a75e0c61ceab82f41b29 100644 (file)
@@ -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
index e5035e05698827fb0af13e0d3503110bbe79fbd8..1da67ccddfc57dde8067e04689b9cbf034d39a8d 100644 (file)
@@ -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
index aa616515b21ad0d418a1d66de3015b5b104d346e..616d17b0c07e104f149ffff14f0774d2044c458b 100644 (file)
    */
 
 /* 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);
 }
index bd7e21efd806941d9684bef48ad24a2cee713223..e5cdc2603999230642088d8587f13723a1e8bc85 100644 (file)
@@ -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; })