*: better string sharing
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 2 Jun 2010 10:57:26 +0000 (12:57 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 2 Jun 2010 10:57:26 +0000 (12:57 +0200)
   text   data    bss    dec    hex filename
 849427    441   7556 857424  d1550 busybox_old
 849355    441   7556 857352  d1508 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/bzip2.c
archival/libunarchive/decompress_unxz.c
archival/libunarchive/decompress_unzip.c
coreutils/head.c
coreutils/od_bloaty.c
coreutils/tail.c
miscutils/less.c
modutils/modutils-24.c
shell/ash.c
util-linux/fdisk.c

index f1c84d6..fdb8b93 100644 (file)
@@ -88,7 +88,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
                        if (n2 != n) {
                                if (n2 >= 0)
                                        errno = 0; /* prevent bogus error message */
-                               bb_perror_msg(n2 >= 0 ? "short write" : "write error");
+                               bb_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
                                return -1;
                        }
                }
@@ -118,7 +118,7 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(unpack_info_t *info UNUSED_PA
        while (1) {
                count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
                if (count < 0) {
-                       bb_perror_msg("read error");
+                       bb_perror_msg(bb_msg_read_error);
                        total = -1;
                        break;
                }
index 3f93929..1302e29 100644 (file)
@@ -86,7 +86,7 @@ unpack_xz_stream(int src_fd, int dst_fd)
                if (rd) {
                        rd = safe_read(src_fd, membuf + insz, rd);
                        if (rd < 0) {
-                               bb_error_msg("read error");
+                               bb_error_msg(bb_msg_read_error);
                                total = -1;
                                break;
                        }
index 33e877e..bccd026 100644 (file)
@@ -1072,7 +1072,7 @@ static int top_up(STATE_PARAM unsigned n)
                bytebuffer_offset = 0;
                bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
                if ((int)bytebuffer_size < 0) {
-                       bb_error_msg("read error");
+                       bb_error_msg(bb_msg_read_error);
                        return 0;
                }
                bytebuffer_size += count;
index 75189ed..cc28374 100644 (file)
@@ -27,7 +27,7 @@ static const struct suffix_mult head_suffixes[] = {
        { "", 0 }
 };
 
-static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n";
+#define header_fmt_str "\n==> %s <==\n"
 
 int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int head_main(int argc, char **argv)
index 6aba0f6..a9a45c8 100644 (file)
@@ -502,7 +502,7 @@ check_and_close(void)
        }
 
        if (ferror(stdout)) {
-               bb_error_msg("write error");
+               bb_error_msg(bb_msg_write_error);
                ioerror = 1;
        }
 }
index 8fc22f5..6397702 100644 (file)
@@ -66,7 +66,7 @@ static ssize_t tail_read(int fd, char *buf, size_t count)
        return r;
 }
 
-static const char header_fmt[] ALIGN1 = "\n==> %s <==\n";
+#define header_fmt_str "\n==> %s <==\n"
 
 static unsigned eat_num(const char *p)
 {
@@ -166,7 +166,7 @@ int tail_main(int argc, char **argv)
        tailbuf = xmalloc(tailbufsize);
 
        /* tail the files */
-       fmt = header_fmt + 1; /* skip header leading newline on first output */
+       fmt = header_fmt_str + 1; /* skip header leading newline on first output */
        i = 0;
        do {
                char *buf;
@@ -181,7 +181,7 @@ int tail_main(int argc, char **argv)
 
                if (nfiles > header_threshhold) {
                        tail_xprint_header(fmt, argv[i]);
-                       fmt = header_fmt;
+                       fmt = header_fmt_str;
                }
 
                if (!from_top) {
@@ -333,7 +333,7 @@ int tail_main(int argc, char **argv)
                        if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
                                continue;
                        if (nfiles > header_threshhold) {
-                               fmt = header_fmt;
+                               fmt = header_fmt_str;
                        }
                        while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) {
                                if (fmt) {
index 8482662..da2cd07 100644 (file)
@@ -430,7 +430,7 @@ static void read_lines(void)
                                         * immediately */
                                        eof_error = 1;
                                } else {
-                                       print_statusline("read error");
+                                       print_statusline(bb_msg_read_error);
                                }
                        }
 #if !ENABLE_FEATURE_LESS_REGEXP
index 5c1611c..7f39e25 100644 (file)
@@ -3529,20 +3529,18 @@ static void set_tainted(int fd, const char *m_name,
 /* Check if loading this module will taint the kernel. */
 static void check_tainted_module(struct obj_file *f, const char *m_name)
 {
-       static const char tainted_file[] ALIGN1 = TAINT_FILENAME;
-
        int fd, kernel_has_tainted;
        const char *ptr;
 
        kernel_has_tainted = 1;
-       fd = open(tainted_file, O_RDWR);
+       fd = open(TAINT_FILENAME, O_RDWR);
        if (fd < 0) {
                if (errno == ENOENT)
                        kernel_has_tainted = 0;
                else if (errno == EACCES)
                        kernel_has_tainted = 1;
                else {
-                       perror(tainted_file);
+                       perror(TAINT_FILENAME);
                        kernel_has_tainted = 0;
                }
        }
index d77d9d3..08ad0f4 100644 (file)
@@ -119,9 +119,7 @@ enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
 
 /* ============ Misc data */
 
-static const char homestr[] ALIGN1 = "HOME";
-static const char snlfmt[] ALIGN1 = "%s\n";
-static const char msg_illnum[] ALIGN1 = "Illegal number: %s";
+#define msg_illnum "Illegal number: %s"
 
 /*
  * We enclose jmp_buf in a structure so that we can declare pointers to
@@ -2520,7 +2518,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
        flags = cdopt();
        dest = *argptr;
        if (!dest)
-               dest = bltinlookup(homestr);
+               dest = bltinlookup("HOME");
        else if (LONE_DASH(dest)) {
                dest = bltinlookup("OLDPWD");
                flags |= CD_PRINT;
@@ -2567,7 +2565,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
        /* NOTREACHED */
  out:
        if (flags & CD_PRINT)
-               out1fmt(snlfmt, curdir);
+               out1fmt("%s\n", curdir);
        return 0;
 }
 
@@ -2583,7 +2581,7 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                        setpwd(dir, 0);
                dir = physdir;
        }
-       out1fmt(snlfmt, dir);
+       out1fmt("%s\n", dir);
        return 0;
 }
 
@@ -5625,7 +5623,7 @@ exptilde(char *startp, char *p, int flags)
  done:
        *p = '\0';
        if (*name == '\0') {
-               home = lookupvar(homestr);
+               home = lookupvar("HOME");
        } else {
                pw = getpwnam(name);
                if (pw == NULL)
@@ -9857,7 +9855,7 @@ chkmail(void)
                }
                if (!mail_var_path_changed && statb.st_mtime != *mtp) {
                        fprintf(
-                               stderr, snlfmt,
+                               stderr, "%s\n",
                                pathopt ? pathopt : "you have mail"
                        );
                }
index 8e13317..7227a82 100644 (file)
@@ -107,9 +107,9 @@ struct partition {
        unsigned char size4[4];         /* nr of sectors in partition */
 } PACKED;
 
-static const char unable_to_open[] ALIGN1 = "can't open '%s'";
-static const char unable_to_read[] ALIGN1 = "can't read from %s";
-static const char unable_to_seek[] ALIGN1 = "can't seek on %s";
+#define unable_to_open "can't open '%s'"
+#define unable_to_read "can't read from %s"
+#define unable_to_seek "can't seek on %s"
 
 enum label_type {
        LABEL_DOS, LABEL_SUN, LABEL_SGI, LABEL_AIX, LABEL_OSF