aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/bzip2.c4
-rw-r--r--archival/libunarchive/decompress_unxz.c2
-rw-r--r--archival/libunarchive/decompress_unzip.c2
-rw-r--r--archival/rpm2cpio.c19
-rw-r--r--coreutils/head.c2
-rw-r--r--coreutils/od_bloaty.c2
-rw-r--r--coreutils/tail.c8
-rw-r--r--coreutils/test.c2
-rw-r--r--docs/keep_data_small.txt5
-rw-r--r--include/unarchive.h16
-rw-r--r--libbb/read.c21
-rw-r--r--miscutils/less.c2
-rw-r--r--modutils/modutils-24.c6
-rw-r--r--shell/ash.c14
-rw-r--r--util-linux/fdisk.c6
15 files changed, 69 insertions, 42 deletions
diff --git a/archival/bzip2.c b/archival/bzip2.c
index f1c84d681..fdb8b9306 100644
--- a/archival/bzip2.c
+++ b/archival/bzip2.c
@@ -88,7 +88,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
88 if (n2 != n) { 88 if (n2 != n) {
89 if (n2 >= 0) 89 if (n2 >= 0)
90 errno = 0; /* prevent bogus error message */ 90 errno = 0; /* prevent bogus error message */
91 bb_perror_msg(n2 >= 0 ? "short write" : "write error"); 91 bb_perror_msg(n2 >= 0 ? "short write" : bb_msg_write_error);
92 return -1; 92 return -1;
93 } 93 }
94 } 94 }
@@ -118,7 +118,7 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(unpack_info_t *info UNUSED_PA
118 while (1) { 118 while (1) {
119 count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE); 119 count = full_read(STDIN_FILENO, rbuf, IOBUF_SIZE);
120 if (count < 0) { 120 if (count < 0) {
121 bb_perror_msg("read error"); 121 bb_perror_msg(bb_msg_read_error);
122 total = -1; 122 total = -1;
123 break; 123 break;
124 } 124 }
diff --git a/archival/libunarchive/decompress_unxz.c b/archival/libunarchive/decompress_unxz.c
index 3f9392984..1302e29fb 100644
--- a/archival/libunarchive/decompress_unxz.c
+++ b/archival/libunarchive/decompress_unxz.c
@@ -86,7 +86,7 @@ unpack_xz_stream(int src_fd, int dst_fd)
86 if (rd) { 86 if (rd) {
87 rd = safe_read(src_fd, membuf + insz, rd); 87 rd = safe_read(src_fd, membuf + insz, rd);
88 if (rd < 0) { 88 if (rd < 0) {
89 bb_error_msg("read error"); 89 bb_error_msg(bb_msg_read_error);
90 total = -1; 90 total = -1;
91 break; 91 break;
92 } 92 }
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 33e877ec8..bccd0262e 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -1072,7 +1072,7 @@ static int top_up(STATE_PARAM unsigned n)
1072 bytebuffer_offset = 0; 1072 bytebuffer_offset = 0;
1073 bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count); 1073 bytebuffer_size = full_read(gunzip_src_fd, &bytebuffer[count], bytebuffer_max - count);
1074 if ((int)bytebuffer_size < 0) { 1074 if ((int)bytebuffer_size < 0) {
1075 bb_error_msg("read error"); 1075 bb_error_msg(bb_msg_read_error);
1076 return 0; 1076 return 0;
1077 } 1077 }
1078 bytebuffer_size += count; 1078 bytebuffer_size += count;
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 598ec8670..1c67dcc6e 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -68,26 +68,31 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
68#else 68#else
69 /* BLOAT */ 69 /* BLOAT */
70 { 70 {
71 unsigned char magic[8]; 71 union {
72 uint8_t b[4];
73 uint16_t b16[2];
74 uint32_t b32[1];
75 } magic;
72 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd); 76 IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
73 77
74 xread(rpm_fd, &magic, 2); 78 xread(rpm_fd, magic.b16, sizeof(magic.b16));
75 if (magic[0] == 0x1f && magic[1] == 0x8b) { 79 if (magic.b16[0] == GZIP_MAGIC) {
76 unpack = unpack_gz_stream; 80 unpack = unpack_gz_stream;
77 } else 81 } else
78 if (ENABLE_FEATURE_SEAMLESS_BZ2 82 if (ENABLE_FEATURE_SEAMLESS_BZ2
79 && magic[0] == 'B' && magic[1] == 'Z' 83 && magic.b16[0] == BZIP2_MAGIC
80 ) { 84 ) {
81 unpack = unpack_bz2_stream; 85 unpack = unpack_bz2_stream;
82 } else 86 } else
83 if (ENABLE_FEATURE_SEAMLESS_XZ 87 if (ENABLE_FEATURE_SEAMLESS_XZ
84 && magic[0] == 0xfd && magic[1] == '7' 88 && magic.b16[0] == XZ_MAGIC1
85 ) { 89 ) {
86 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */ 90 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */
87 /* More info at: http://tukaani.org/xz/xz-file-format.txt */ 91 /* More info at: http://tukaani.org/xz/xz-file-format.txt */
88 xread(rpm_fd, magic + 2, 4); 92 xread(rpm_fd, magic.b32, sizeof(magic.b32));
89 if (strcmp((char*)magic + 2, "zXZ") != 0) 93 if (magic.b32[0] != XZ_MAGIC2)
90 goto no_magic; 94 goto no_magic;
95 /* unpack_xz_stream wants fd at position 0 */
91 xlseek(rpm_fd, -6, SEEK_CUR); 96 xlseek(rpm_fd, -6, SEEK_CUR);
92 unpack = unpack_xz_stream; 97 unpack = unpack_xz_stream;
93 } else { 98 } else {
diff --git a/coreutils/head.c b/coreutils/head.c
index 75189eda8..cc2837411 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -27,7 +27,7 @@ static const struct suffix_mult head_suffixes[] = {
27 { "", 0 } 27 { "", 0 }
28}; 28};
29 29
30static const char header_fmt_str[] ALIGN1 = "\n==> %s <==\n"; 30#define header_fmt_str "\n==> %s <==\n"
31 31
32int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 32int head_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
33int head_main(int argc, char **argv) 33int head_main(int argc, char **argv)
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index cb97ff8c5..4c6b64d5e 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -509,7 +509,7 @@ check_and_close(void)
509 } 509 }
510 510
511 if (ferror(stdout)) { 511 if (ferror(stdout)) {
512 bb_error_msg("write error"); 512 bb_error_msg(bb_msg_write_error);
513 ioerror = 1; 513 ioerror = 1;
514 } 514 }
515} 515}
diff --git a/coreutils/tail.c b/coreutils/tail.c
index 8fc22f562..6397702a0 100644
--- a/coreutils/tail.c
+++ b/coreutils/tail.c
@@ -66,7 +66,7 @@ static ssize_t tail_read(int fd, char *buf, size_t count)
66 return r; 66 return r;
67} 67}
68 68
69static const char header_fmt[] ALIGN1 = "\n==> %s <==\n"; 69#define header_fmt_str "\n==> %s <==\n"
70 70
71static unsigned eat_num(const char *p) 71static unsigned eat_num(const char *p)
72{ 72{
@@ -166,7 +166,7 @@ int tail_main(int argc, char **argv)
166 tailbuf = xmalloc(tailbufsize); 166 tailbuf = xmalloc(tailbufsize);
167 167
168 /* tail the files */ 168 /* tail the files */
169 fmt = header_fmt + 1; /* skip header leading newline on first output */ 169 fmt = header_fmt_str + 1; /* skip header leading newline on first output */
170 i = 0; 170 i = 0;
171 do { 171 do {
172 char *buf; 172 char *buf;
@@ -181,7 +181,7 @@ int tail_main(int argc, char **argv)
181 181
182 if (nfiles > header_threshhold) { 182 if (nfiles > header_threshhold) {
183 tail_xprint_header(fmt, argv[i]); 183 tail_xprint_header(fmt, argv[i]);
184 fmt = header_fmt; 184 fmt = header_fmt_str;
185 } 185 }
186 186
187 if (!from_top) { 187 if (!from_top) {
@@ -333,7 +333,7 @@ int tail_main(int argc, char **argv)
333 if (ENABLE_FEATURE_FANCY_TAIL && fd < 0) 333 if (ENABLE_FEATURE_FANCY_TAIL && fd < 0)
334 continue; 334 continue;
335 if (nfiles > header_threshhold) { 335 if (nfiles > header_threshhold) {
336 fmt = header_fmt; 336 fmt = header_fmt_str;
337 } 337 }
338 while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) { 338 while ((nread = tail_read(fd, tailbuf, BUFSIZ)) > 0) {
339 if (fmt) { 339 if (fmt) {
diff --git a/coreutils/test.c b/coreutils/test.c
index 3115ce6e7..0b9322316 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -393,7 +393,7 @@ static number_t getn(const char *s)
393 if (errno != 0) 393 if (errno != 0)
394 syntax(s, "out of range"); 394 syntax(s, "out of range");
395 395
396 if (*(skip_whitespace(p))) 396 if (p == s || *(skip_whitespace(p)) != '\0')
397 syntax(s, "bad number"); 397 syntax(s, "bad number");
398 398
399 return r; 399 return r;
diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt
index 079bac3a6..01c0d3c7b 100644
--- a/docs/keep_data_small.txt
+++ b/docs/keep_data_small.txt
@@ -145,6 +145,11 @@ one of above methods is not worth the resulting code obfuscation.
145If you have less than ~300 bytes of global data - don't bother. 145If you have less than ~300 bytes of global data - don't bother.
146 146
147 147
148 Finding non-shared duplicated strings
149
150strings busybox | sort | uniq -c | sort -nr
151
152
148 gcc's data alignment problem 153 gcc's data alignment problem
149 154
150The following attribute added in vi.c: 155The following attribute added in vi.c:
diff --git a/include/unarchive.h b/include/unarchive.h
index aa7ecec55..8009de282 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -4,6 +4,22 @@
4 4
5PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 5PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
6 6
7enum {
8#if BB_BIG_ENDIAN
9 COMPRESS_MAGIC = 0x1f9d,
10 GZIP_MAGIC = 0x1f8b,
11 BZIP2_MAGIC = ('B'<<8) + 'Z',
12 XZ_MAGIC1 = (0xfd<<8) + '7',
13 XZ_MAGIC2 = ((((('z'<<8) + 'X')<<8) + 'Z')<<8) + 0,
14#else
15 COMPRESS_MAGIC = 0x9d1f,
16 GZIP_MAGIC = 0x8b1f,
17 BZIP2_MAGIC = ('Z'<<8) + 'B',
18 XZ_MAGIC1 = ('7'<<8) + 0xfd,
19 XZ_MAGIC2 = (((((0<<8) + 'Z')<<8) + 'X')<<8) + 'z',
20#endif
21};
22
7typedef struct file_header_t { 23typedef struct file_header_t {
8 char *name; 24 char *name;
9 char *link_target; 25 char *link_target;
diff --git a/libbb/read.c b/libbb/read.c
index cd6bbeb13..b1eb3f24b 100644
--- a/libbb/read.c
+++ b/libbb/read.c
@@ -312,7 +312,11 @@ void* FAST_FUNC xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p)
312void FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) 312void FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/)
313{ 313{
314 const int fail_if_not_detected = 1; 314 const int fail_if_not_detected = 1;
315 unsigned char magic[8]; 315 union {
316 uint8_t b[4];
317 uint16_t b16[2];
318 uint32_t b32[1];
319 } magic;
316 int offset = -2; 320 int offset = -2;
317# if BB_MMU 321# if BB_MMU
318 IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd); 322 IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd);
@@ -324,9 +328,9 @@ void FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/)
324 328
325 /* .gz and .bz2 both have 2-byte signature, and their 329 /* .gz and .bz2 both have 2-byte signature, and their
326 * unpack_XXX_stream wants this header skipped. */ 330 * unpack_XXX_stream wants this header skipped. */
327 xread(fd, magic, 2); 331 xread(fd, magic.b16, sizeof(magic.b16));
328 if (ENABLE_FEATURE_SEAMLESS_GZ 332 if (ENABLE_FEATURE_SEAMLESS_GZ
329 && magic[0] == 0x1f && magic[1] == 0x8b 333 && magic.b16[0] == GZIP_MAGIC
330 ) { 334 ) {
331# if BB_MMU 335# if BB_MMU
332 xformer = unpack_gz_stream; 336 xformer = unpack_gz_stream;
@@ -336,7 +340,7 @@ void FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/)
336 goto found_magic; 340 goto found_magic;
337 } 341 }
338 if (ENABLE_FEATURE_SEAMLESS_BZ2 342 if (ENABLE_FEATURE_SEAMLESS_BZ2
339 && magic[0] == 'B' && magic[1] == 'Z' 343 && magic.b16[0] == BZIP2_MAGIC
340 ) { 344 ) {
341# if BB_MMU 345# if BB_MMU
342 xformer = unpack_bz2_stream; 346 xformer = unpack_bz2_stream;
@@ -346,19 +350,20 @@ void FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/)
346 goto found_magic; 350 goto found_magic;
347 } 351 }
348 if (ENABLE_FEATURE_SEAMLESS_XZ 352 if (ENABLE_FEATURE_SEAMLESS_XZ
349 && magic[0] == 0xfd && magic[1] == '7' 353 && magic.b16[0] == XZ_MAGIC1
350 ) { 354 ) {
351 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */ 355 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */
352 /* More info at: http://tukaani.org/xz/xz-file-format.txt */ 356 /* More info at: http://tukaani.org/xz/xz-file-format.txt */
353 offset = -6; 357 offset = -6;
354 xread(fd, magic + 2, 4); 358 xread(fd, magic.b32, sizeof(magic.b32));
355 if (strcmp((char*)magic + 2, "zXZ") == 0) { 359 if (magic.b32[0] == XZ_MAGIC2) {
356# if BB_MMU 360# if BB_MMU
357 xformer = unpack_xz_stream; 361 xformer = unpack_xz_stream;
362 /* unpack_xz_stream wants fd at position 0 */
363 xlseek(fd, offset, SEEK_CUR);
358# else 364# else
359 xformer_prog = "unxz"; 365 xformer_prog = "unxz";
360# endif 366# endif
361 xlseek(fd, offset, SEEK_CUR);
362 goto found_magic; 367 goto found_magic;
363 } 368 }
364 } 369 }
diff --git a/miscutils/less.c b/miscutils/less.c
index 848266212..da2cd07af 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -430,7 +430,7 @@ static void read_lines(void)
430 * immediately */ 430 * immediately */
431 eof_error = 1; 431 eof_error = 1;
432 } else { 432 } else {
433 print_statusline("read error"); 433 print_statusline(bb_msg_read_error);
434 } 434 }
435 } 435 }
436#if !ENABLE_FEATURE_LESS_REGEXP 436#if !ENABLE_FEATURE_LESS_REGEXP
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c
index 5c1611c29..7f39e253d 100644
--- a/modutils/modutils-24.c
+++ b/modutils/modutils-24.c
@@ -3529,20 +3529,18 @@ static void set_tainted(int fd, const char *m_name,
3529/* Check if loading this module will taint the kernel. */ 3529/* Check if loading this module will taint the kernel. */
3530static void check_tainted_module(struct obj_file *f, const char *m_name) 3530static void check_tainted_module(struct obj_file *f, const char *m_name)
3531{ 3531{
3532 static const char tainted_file[] ALIGN1 = TAINT_FILENAME;
3533
3534 int fd, kernel_has_tainted; 3532 int fd, kernel_has_tainted;
3535 const char *ptr; 3533 const char *ptr;
3536 3534
3537 kernel_has_tainted = 1; 3535 kernel_has_tainted = 1;
3538 fd = open(tainted_file, O_RDWR); 3536 fd = open(TAINT_FILENAME, O_RDWR);
3539 if (fd < 0) { 3537 if (fd < 0) {
3540 if (errno == ENOENT) 3538 if (errno == ENOENT)
3541 kernel_has_tainted = 0; 3539 kernel_has_tainted = 0;
3542 else if (errno == EACCES) 3540 else if (errno == EACCES)
3543 kernel_has_tainted = 1; 3541 kernel_has_tainted = 1;
3544 else { 3542 else {
3545 perror(tainted_file); 3543 perror(TAINT_FILENAME);
3546 kernel_has_tainted = 0; 3544 kernel_has_tainted = 0;
3547 } 3545 }
3548 } 3546 }
diff --git a/shell/ash.c b/shell/ash.c
index 54a831f6d..913f40f12 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -168,9 +168,7 @@ enum { NOPTS = ARRAY_SIZE(optletters_optnames) };
168 168
169/* ============ Misc data */ 169/* ============ Misc data */
170 170
171static const char homestr[] ALIGN1 = "HOME"; 171#define msg_illnum "Illegal number: %s"
172static const char snlfmt[] ALIGN1 = "%s\n";
173static const char msg_illnum[] ALIGN1 = "Illegal number: %s";
174 172
175/* 173/*
176 * We enclose jmp_buf in a structure so that we can declare pointers to 174 * We enclose jmp_buf in a structure so that we can declare pointers to
@@ -2674,7 +2672,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2674 flags = cdopt(); 2672 flags = cdopt();
2675 dest = *argptr; 2673 dest = *argptr;
2676 if (!dest) 2674 if (!dest)
2677 dest = bltinlookup(homestr); 2675 dest = bltinlookup("HOME");
2678 else if (LONE_DASH(dest)) { 2676 else if (LONE_DASH(dest)) {
2679 dest = bltinlookup("OLDPWD"); 2677 dest = bltinlookup("OLDPWD");
2680 flags |= CD_PRINT; 2678 flags |= CD_PRINT;
@@ -2721,7 +2719,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2721 /* NOTREACHED */ 2719 /* NOTREACHED */
2722 out: 2720 out:
2723 if (flags & CD_PRINT) 2721 if (flags & CD_PRINT)
2724 out1fmt(snlfmt, curdir); 2722 out1fmt("%s\n", curdir);
2725 return 0; 2723 return 0;
2726} 2724}
2727 2725
@@ -2737,7 +2735,7 @@ pwdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
2737 setpwd(dir, 0); 2735 setpwd(dir, 0);
2738 dir = physdir; 2736 dir = physdir;
2739 } 2737 }
2740 out1fmt(snlfmt, dir); 2738 out1fmt("%s\n", dir);
2741 return 0; 2739 return 0;
2742} 2740}
2743 2741
@@ -5915,7 +5913,7 @@ exptilde(char *startp, char *p, int flags)
5915 done: 5913 done:
5916 *p = '\0'; 5914 *p = '\0';
5917 if (*name == '\0') { 5915 if (*name == '\0') {
5918 home = lookupvar(homestr); 5916 home = lookupvar("HOME");
5919 } else { 5917 } else {
5920 if (ENABLE_PLATFORM_MINGW32) 5918 if (ENABLE_PLATFORM_MINGW32)
5921 goto lose; 5919 goto lose;
@@ -10322,7 +10320,7 @@ chkmail(void)
10322 } 10320 }
10323 if (!mail_var_path_changed && statb.st_mtime != *mtp) { 10321 if (!mail_var_path_changed && statb.st_mtime != *mtp) {
10324 fprintf( 10322 fprintf(
10325 stderr, snlfmt, 10323 stderr, "%s\n",
10326 pathopt ? pathopt : "you have mail" 10324 pathopt ? pathopt : "you have mail"
10327 ); 10325 );
10328 } 10326 }
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 8e133178d..7227a829e 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -107,9 +107,9 @@ struct partition {
107 unsigned char size4[4]; /* nr of sectors in partition */ 107 unsigned char size4[4]; /* nr of sectors in partition */
108} PACKED; 108} PACKED;
109 109
110static const char unable_to_open[] ALIGN1 = "can't open '%s'"; 110#define unable_to_open "can't open '%s'"
111static const char unable_to_read[] ALIGN1 = "can't read from %s"; 111#define unable_to_read "can't read from %s"
112static const char unable_to_seek[] ALIGN1 = "can't seek on %s"; 112#define unable_to_seek "can't seek on %s"
113 113
114enum label_type { 114enum label_type {
115 LABEL_DOS, LABEL_SUN, LABEL_SGI, LABEL_AIX, LABEL_OSF 115 LABEL_DOS, LABEL_SUN, LABEL_SGI, LABEL_AIX, LABEL_OSF