aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-05-21 18:38:59 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-05-21 18:38:59 +0200
commit9d96e274ce1fac0e82d850075acc87cd5e97fc39 (patch)
treef87b1f827aaeaf24022d4e04a685eaa164ead913 /coreutils
parent3ef344be91b153f863b91afdf6b0a0e441ac4ac7 (diff)
downloadbusybox-w32-9d96e274ce1fac0e82d850075acc87cd5e97fc39.tar.gz
busybox-w32-9d96e274ce1fac0e82d850075acc87cd5e97fc39.tar.bz2
busybox-w32-9d96e274ce1fac0e82d850075acc87cd5e97fc39.zip
od: fix -S NUM to not print chars >0x80
function old new delta write_block 433 431 -2 print_ascii 217 215 -2 check_and_close 104 96 -8 od_main 2164 2139 -25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/od_bloaty.c57
1 files changed, 19 insertions, 38 deletions
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 96a4186e2..8ed8f0be4 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -70,7 +70,7 @@ enum {
70 70
71 71
72/* Check for 0x7f is a coreutils 6.3 addition */ 72/* Check for 0x7f is a coreutils 6.3 addition */
73#define ISPRINT(c) (((c)>=' ') && (c) != 0x7f) 73#define ISPRINT(c) (((c) >= ' ') && (c) < 0x7f)
74 74
75typedef long double longdouble_t; 75typedef long double longdouble_t;
76typedef unsigned long long ulonglong_t; 76typedef unsigned long long ulonglong_t;
@@ -176,7 +176,7 @@ struct ERR_width_bytes_has_bad_size {
176 176
177static smallint exit_code; 177static smallint exit_code;
178 178
179static size_t string_min; 179static unsigned string_min;
180 180
181/* An array of specs describing how to format each input block. */ 181/* An array of specs describing how to format each input block. */
182static size_t n_specs; 182static size_t n_specs;
@@ -514,8 +514,7 @@ check_and_close(void)
514 } 514 }
515 515
516 if (ferror(stdout)) { 516 if (ferror(stdout)) {
517 bb_error_msg(bb_msg_write_error); 517 bb_error_msg_and_die(bb_msg_write_error);
518 exit_code = 1;
519 } 518 }
520} 519}
521 520
@@ -1043,29 +1042,6 @@ dump(off_t current_offset, off_t end_offset)
1043 free(block[0]); 1042 free(block[0]);
1044} 1043}
1045 1044
1046/* Read a single byte into *C from the concatenation of the input files
1047 named in the global array FILE_LIST. On the first call to this
1048 function, the global variable IN_STREAM is expected to be an open
1049 stream associated with the input file INPUT_FILENAME. If IN_STREAM
1050 is at end-of-file, close it and update the global variables IN_STREAM
1051 and INPUT_FILENAME so they correspond to the next file in the list.
1052 Then try to read a byte from the newly opened file. Repeat if
1053 necessary until EOF is reached for the last file in FILE_LIST, then
1054 set *C to EOF and return. Subsequent calls do likewise. */
1055
1056static void
1057read_char(int *c)
1058{
1059 while (in_stream) { /* !EOF */
1060 *c = fgetc(in_stream);
1061 if (*c != EOF)
1062 return;
1063 check_and_close();
1064 open_next_file();
1065 }
1066 *c = EOF;
1067}
1068
1069/* Read N bytes into BLOCK from the concatenation of the input files 1045/* Read N bytes into BLOCK from the concatenation of the input files
1070 named in the global array FILE_LIST. On the first call to this 1046 named in the global array FILE_LIST. On the first call to this
1071 function, the global variable IN_STREAM is expected to be an open 1047 function, the global variable IN_STREAM is expected to be an open
@@ -1089,8 +1065,8 @@ read_char(int *c)
1089static void 1065static void
1090dump_strings(off_t address, off_t end_offset) 1066dump_strings(off_t address, off_t end_offset)
1091{ 1067{
1092 size_t bufsize = MAX(100, string_min); 1068 unsigned bufsize = MAX(100, string_min);
1093 char *buf = xmalloc(bufsize); 1069 unsigned char *buf = xmalloc(bufsize);
1094 1070
1095 while (1) { 1071 while (1) {
1096 size_t i; 1072 size_t i;
@@ -1106,11 +1082,17 @@ dump_strings(off_t address, off_t end_offset)
1106 bufsize += bufsize/8; 1082 bufsize += bufsize/8;
1107 buf = xrealloc(buf, bufsize); 1083 buf = xrealloc(buf, bufsize);
1108 } 1084 }
1109 read_char(&c); 1085
1110 if (c < 0) { /* EOF */ 1086 while (in_stream) { /* !EOF */
1111 free(buf); 1087 c = fgetc(in_stream);
1112 return; 1088 if (c != EOF)
1089 goto got_char;
1090 check_and_close();
1091 open_next_file();
1113 } 1092 }
1093 /* EOF */
1094 goto ret;
1095 got_char:
1114 address++; 1096 address++;
1115 if (!c) 1097 if (!c)
1116 break; 1098 break;
@@ -1122,8 +1104,7 @@ dump_strings(off_t address, off_t end_offset)
1122 if (i < string_min) /* Too short! */ 1104 if (i < string_min) /* Too short! */
1123 goto tryline; 1105 goto tryline;
1124 1106
1125 /* If we get here, the string is all printable and NUL-terminated, 1107 /* If we get here, the string is all printable and NUL-terminated */
1126 * so print it. It is all in 'buf' and 'i' is its length. */
1127 buf[i] = 0; 1108 buf[i] = 0;
1128 format_address(address - i - 1, ' '); 1109 format_address(address - i - 1, ' ');
1129 1110
@@ -1144,9 +1125,9 @@ dump_strings(off_t address, off_t end_offset)
1144 1125
1145 /* We reach this point only if we search through 1126 /* We reach this point only if we search through
1146 (max_bytes_to_format - string_min) bytes before reaching EOF. */ 1127 (max_bytes_to_format - string_min) bytes before reaching EOF. */
1147 free(buf);
1148
1149 check_and_close(); 1128 check_and_close();
1129 ret:
1130 free(buf);
1150} 1131}
1151 1132
1152#if ENABLE_LONG_OPTS 1133#if ENABLE_LONG_OPTS
@@ -1397,7 +1378,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
1397 else 1378 else
1398 dump(n_bytes_to_skip, end_offset); 1379 dump(n_bytes_to_skip, end_offset);
1399 1380
1400 if (fclose(stdin) == EOF) 1381 if (fclose(stdin))
1401 bb_perror_msg_and_die(bb_msg_standard_input); 1382 bb_perror_msg_and_die(bb_msg_standard_input);
1402 1383
1403 return exit_code; 1384 return exit_code;