]> mj.ucw.cz Git - libucw.git/commitdiff
Use `char *' instead of `byte *' for strings
authorMartin Mares <mj@ucw.cz>
Fri, 22 Jun 2007 09:31:26 +0000 (11:31 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 22 Jun 2007 09:31:26 +0000 (11:31 +0200)
at places where it is straight-forward.

18 files changed:
lib/exitstatus.c
lib/lfs.h
lib/lib.h
lib/mainloop.h
lib/md5hex.c
lib/mmap.c
lib/partmap.c
lib/partmap.h
lib/profile.h
lib/qache.c
lib/qache.h
lib/regex.c
lib/runcmd.c
lib/semaphore.h
lib/stkstring.h
lib/string.c
lib/sync.c
lib/wordsplit.c

index 4dce53d003bf0d46399771fd8f64bac8662f4fb1..1095c7ff73e138445f1f4c736df787c4a046eda3 100644 (file)
@@ -14,7 +14,7 @@
 #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);
index ec588e65352d8760c80c8aa294e1363425ee9006..ede41268691578370d490c229013ac6adc3cd250 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(const byte *name)
+sh_file_size(const char *name)
 {
   int fd = sh_open(name, O_RDONLY);
   if (fd < 0)
index e7916a11220eae6d6da8dcb1e3e371cceaaeb8e4..6e74b6f57728b66be8be6301a593543e66c0fa8e 100644 (file)
--- 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 */
 
index f321c2b5fc85e57402d1a4c2741b1deea26f2bcd..aca8914fce9671fb27c3e30457c307410ca65013 100644 (file)
@@ -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 */
 };
index 5f2e8ebba8aed5f18e0ac8466c05d10ba932f1d6..93987b00a13246de55581ded5dd415dae163b10a 100644 (file)
@@ -13,7 +13,7 @@
 #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++)
@@ -21,7 +21,7 @@ md5_to_hex(const byte *s, byte *d)
 }
 
 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++)
index e2ea6ff6a5dde5cefb5801ee009c5431201d4686..928da4bc176266a694276f93aa102801e4014e08 100644 (file)
@@ -16,7 +16,7 @@
 #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;
index baaef9c2129b70fa98ffe76a2c1d0f31a3911f56..2b70f1d916f6e16e0235687f0f51007aac44f849 100644 (file)
@@ -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));
 
index 1be70ded414e3977e2863be99b8c049120da0c32..985b36267ade51bfa2def9893fd5b985b8dd72e9 100644 (file)
@@ -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);
index c3c29df1faf6a7e2377813fd93b43a62c86b5da1..3704b449e6294e4d0599f0529c5cd44f1a620f74 100644 (file)
@@ -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
 
index 854a12df6353520e671576ffa22ea3c1ef9b6990..91536bf7a0df2d9d5a259df63680dcb03fafb0c6 100644 (file)
@@ -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; i<sizeof(qache_key_t); i++)
     sprintf(keybuf+2*i, "%02x", (*key)[i]);
   return keybuf;
@@ -128,7 +128,7 @@ enum entry_audit_flags {
   ET_HASH = 4
 };
 
-static byte *
+static char *
 audit_entries(struct qache *q, byte *entrymap)
 {
   uns i, j;
@@ -184,7 +184,7 @@ enum block_audit_flags {
   BT_ALLOC = 2
 };
 
-static byte *
+static char *
 audit_blocks(struct qache *q, byte *entrymap, byte *blockmap)
 {
   uns i, j;
@@ -226,7 +226,7 @@ audit_blocks(struct qache *q, byte *entrymap, byte *blockmap)
   return NULL;
 }
 
-static byte *
+static char *
 do_audit(struct qache *q)
 {
   byte *entry_map = xmalloc_zero(q->hdr->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);
index 48a9e31c10bc8808860ce4d0a76acfbe46a6d8dd..5c242a45b460d7d8bab30c3c3f916203990c6c49 100644 (file)
@@ -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 */
index adff133e38138964da5a7256076f17fecfe70783..3baf297e9e003eefb4b0e5ca828a74c060de3730 100644 (file)
@@ -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"))
index c18dcab17e51e1b17c9eaf53410935ec93778660..0204e1db8fb7cea46d0f9d275699eef4d530d0b1 100644 (file)
 #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)
@@ -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);
index d33280bda725f60507309c2ffd87d416f2f75b44..fa2e0ee473d58318e59bc3683d22eb33d94a8895 100644 (file)
@@ -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);
index e5cdc2603999230642088d8587f13723a1e8bc85..49431c181a9809fc3954c10ec8ac046b3536f0c8 100644 (file)
@@ -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);
index 3bc231a67e78a80046ccc43b4eafe0f5e44e7fb5..602a7d730074b24ab3e4a5700994c6fe569580d4 100644 (file)
@@ -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))
index a4c9b05ad1ffdba615505e39950a9e943622d30b..6341415a3c94660799725836c4a3a71ea2dbf658 100644 (file)
@@ -10,7 +10,7 @@
 #include <unistd.h>
 
 void
-sync_dir(const byte *name)
+sync_dir(const char *name)
 {
   int fd = open(name, O_RDONLY
 #ifdef CONFIG_LINUX
index d13f21087792fe8774a56be483dafdc678635924..70984ab58fbe68e02bc7d90ead4828fb53745cf9 100644 (file)
@@ -14,7 +14,7 @@
 #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)