*: better string sharing
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>
diff --git a/archival/bzip2.c b/archival/bzip2.c
index f1c84d6..fdb8b93 100644
--- a/archival/bzip2.c
+++ b/archival/bzip2.c
@@ -88,7 +88,7 @@
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 @@
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;
}
diff --git a/archival/libunarchive/decompress_unxz.c b/archival/libunarchive/decompress_unxz.c
index 3f93929..1302e29 100644
--- a/archival/libunarchive/decompress_unxz.c
+++ b/archival/libunarchive/decompress_unxz.c
@@ -86,7 +86,7 @@
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;
}
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 33e877e..bccd026 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -1072,7 +1072,7 @@
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;
diff --git a/coreutils/head.c b/coreutils/head.c
index 75189ed..cc28374 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -27,7 +27,7 @@
{ "", 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)
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 6aba0f6..a9a45c8 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -502,7 +502,7 @@
}
if (ferror(stdout)) {
- bb_error_msg("write error");
+ bb_error_msg(bb_msg_write_error);
ioerror = 1;
}
}
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 8fc22f5..6397702 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -66,7 +66,7 @@
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 @@
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 @@
if (nfiles > header_threshhold) {
tail_xprint_header(fmt, argv[i]);
- fmt = header_fmt;
+ fmt = header_fmt_str;
}
if (!from_top) {
@@ -333,7 +333,7 @@
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) {
diff --git a/miscutils/less.c b/miscutils/less.c
index 8482662..da2cd07 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -430,7 +430,7 @@
* immediately */
eof_error = 1;
} else {
- print_statusline("read error");
+ print_statusline(bb_msg_read_error);
}
}
#if !ENABLE_FEATURE_LESS_REGEXP
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c
index 5c1611c..7f39e25 100644
--- a/modutils/modutils-24.c
+++ b/modutils/modutils-24.c
@@ -3529,20 +3529,18 @@
/* 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;
}
}
diff --git a/shell/ash.c b/shell/ash.c
index d77d9d3..08ad0f4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -119,9 +119,7 @@
/* ============ 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 @@
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 @@
/* NOTREACHED */
out:
if (flags & CD_PRINT)
- out1fmt(snlfmt, curdir);
+ out1fmt("%s\n", curdir);
return 0;
}
@@ -2583,7 +2581,7 @@
setpwd(dir, 0);
dir = physdir;
}
- out1fmt(snlfmt, dir);
+ out1fmt("%s\n", dir);
return 0;
}
@@ -5625,7 +5623,7 @@
done:
*p = '\0';
if (*name == '\0') {
- home = lookupvar(homestr);
+ home = lookupvar("HOME");
} else {
pw = getpwnam(name);
if (pw == NULL)
@@ -9857,7 +9855,7 @@
}
if (!mail_var_path_changed && statb.st_mtime != *mtp) {
fprintf(
- stderr, snlfmt,
+ stderr, "%s\n",
pathopt ? pathopt : "you have mail"
);
}
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 8e13317..7227a82 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -107,9 +107,9 @@
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