mirror of https://github.com/mirror/busybox.git
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>1_19_stable
parent
3ef344be91
commit
9d96e274ce
|
@ -70,7 +70,7 @@ enum {
|
||||||
|
|
||||||
|
|
||||||
/* Check for 0x7f is a coreutils 6.3 addition */
|
/* Check for 0x7f is a coreutils 6.3 addition */
|
||||||
#define ISPRINT(c) (((c)>=' ') && (c) != 0x7f)
|
#define ISPRINT(c) (((c) >= ' ') && (c) < 0x7f)
|
||||||
|
|
||||||
typedef long double longdouble_t;
|
typedef long double longdouble_t;
|
||||||
typedef unsigned long long ulonglong_t;
|
typedef unsigned long long ulonglong_t;
|
||||||
|
@ -176,7 +176,7 @@ struct ERR_width_bytes_has_bad_size {
|
||||||
|
|
||||||
static smallint exit_code;
|
static smallint exit_code;
|
||||||
|
|
||||||
static size_t string_min;
|
static unsigned string_min;
|
||||||
|
|
||||||
/* An array of specs describing how to format each input block. */
|
/* An array of specs describing how to format each input block. */
|
||||||
static size_t n_specs;
|
static size_t n_specs;
|
||||||
|
@ -514,8 +514,7 @@ check_and_close(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ferror(stdout)) {
|
if (ferror(stdout)) {
|
||||||
bb_error_msg(bb_msg_write_error);
|
bb_error_msg_and_die(bb_msg_write_error);
|
||||||
exit_code = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,29 +1042,6 @@ dump(off_t current_offset, off_t end_offset)
|
||||||
free(block[0]);
|
free(block[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read a single byte into *C from the concatenation of the input files
|
|
||||||
named in the global array FILE_LIST. On the first call to this
|
|
||||||
function, the global variable IN_STREAM is expected to be an open
|
|
||||||
stream associated with the input file INPUT_FILENAME. If IN_STREAM
|
|
||||||
is at end-of-file, close it and update the global variables IN_STREAM
|
|
||||||
and INPUT_FILENAME so they correspond to the next file in the list.
|
|
||||||
Then try to read a byte from the newly opened file. Repeat if
|
|
||||||
necessary until EOF is reached for the last file in FILE_LIST, then
|
|
||||||
set *C to EOF and return. Subsequent calls do likewise. */
|
|
||||||
|
|
||||||
static void
|
|
||||||
read_char(int *c)
|
|
||||||
{
|
|
||||||
while (in_stream) { /* !EOF */
|
|
||||||
*c = fgetc(in_stream);
|
|
||||||
if (*c != EOF)
|
|
||||||
return;
|
|
||||||
check_and_close();
|
|
||||||
open_next_file();
|
|
||||||
}
|
|
||||||
*c = EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read N bytes into BLOCK from the concatenation of the input files
|
/* Read N bytes into BLOCK from the concatenation of the input files
|
||||||
named in the global array FILE_LIST. On the first call to this
|
named in the global array FILE_LIST. On the first call to this
|
||||||
function, the global variable IN_STREAM is expected to be an open
|
function, the global variable IN_STREAM is expected to be an open
|
||||||
|
@ -1089,8 +1065,8 @@ read_char(int *c)
|
||||||
static void
|
static void
|
||||||
dump_strings(off_t address, off_t end_offset)
|
dump_strings(off_t address, off_t end_offset)
|
||||||
{
|
{
|
||||||
size_t bufsize = MAX(100, string_min);
|
unsigned bufsize = MAX(100, string_min);
|
||||||
char *buf = xmalloc(bufsize);
|
unsigned char *buf = xmalloc(bufsize);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -1106,11 +1082,17 @@ dump_strings(off_t address, off_t end_offset)
|
||||||
bufsize += bufsize/8;
|
bufsize += bufsize/8;
|
||||||
buf = xrealloc(buf, bufsize);
|
buf = xrealloc(buf, bufsize);
|
||||||
}
|
}
|
||||||
read_char(&c);
|
|
||||||
if (c < 0) { /* EOF */
|
while (in_stream) { /* !EOF */
|
||||||
free(buf);
|
c = fgetc(in_stream);
|
||||||
return;
|
if (c != EOF)
|
||||||
|
goto got_char;
|
||||||
|
check_and_close();
|
||||||
|
open_next_file();
|
||||||
}
|
}
|
||||||
|
/* EOF */
|
||||||
|
goto ret;
|
||||||
|
got_char:
|
||||||
address++;
|
address++;
|
||||||
if (!c)
|
if (!c)
|
||||||
break;
|
break;
|
||||||
|
@ -1122,8 +1104,7 @@ dump_strings(off_t address, off_t end_offset)
|
||||||
if (i < string_min) /* Too short! */
|
if (i < string_min) /* Too short! */
|
||||||
goto tryline;
|
goto tryline;
|
||||||
|
|
||||||
/* If we get here, the string is all printable and NUL-terminated,
|
/* If we get here, the string is all printable and NUL-terminated */
|
||||||
* so print it. It is all in 'buf' and 'i' is its length. */
|
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
format_address(address - i - 1, ' ');
|
format_address(address - i - 1, ' ');
|
||||||
|
|
||||||
|
@ -1144,9 +1125,9 @@ dump_strings(off_t address, off_t end_offset)
|
||||||
|
|
||||||
/* We reach this point only if we search through
|
/* We reach this point only if we search through
|
||||||
(max_bytes_to_format - string_min) bytes before reaching EOF. */
|
(max_bytes_to_format - string_min) bytes before reaching EOF. */
|
||||||
free(buf);
|
|
||||||
|
|
||||||
check_and_close();
|
check_and_close();
|
||||||
|
ret:
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_LONG_OPTS
|
#if ENABLE_LONG_OPTS
|
||||||
|
@ -1397,7 +1378,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||||
else
|
else
|
||||||
dump(n_bytes_to_skip, end_offset);
|
dump(n_bytes_to_skip, end_offset);
|
||||||
|
|
||||||
if (fclose(stdin) == EOF)
|
if (fclose(stdin))
|
||||||
bb_perror_msg_and_die(bb_msg_standard_input);
|
bb_perror_msg_and_die(bb_msg_standard_input);
|
||||||
|
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
|
Loading…
Reference in New Issue