diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-21 17:22:21 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-21 17:22:21 -0800 |
| commit | 4843f6873f7c4835e62f2c73ba0fd538e57a2f22 (patch) | |
| tree | ee620501a1ffbad9a83141e3a70154e1fe641040 /tools/perf/util/print_binary.c | |
| download | linux-master.tar.gz linux-master.zip | |
Merge tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctlgraftedHEADmaster
Pull sysctl fix from Joel Granados:
"Fix sysctl jiffy / milliseconds conversion:
- Writing a previously read value "X" shall keep the same "X" value
- Remove truncation that was causing incorrect saturation of valid
timeouts"
* tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl:
sysctl: Do jiffy / ms conversion in ulong space
Diffstat (limited to 'tools/perf/util/print_binary.c')
| -rw-r--r-- | tools/perf/util/print_binary.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/perf/util/print_binary.c b/tools/perf/util/print_binary.c new file mode 100644 index 000000000..13fdc51c6 --- /dev/null +++ b/tools/perf/util/print_binary.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "print_binary.h" +#include <linux/log2.h> +#include <linux/ctype.h> + +int binary__fprintf(unsigned char *data, size_t len, + size_t bytes_per_line, binary__fprintf_t printer, + void *extra, FILE *fp) +{ + size_t i, j, mask; + int printed = 0; + + if (!printer) + return 0; + + bytes_per_line = roundup_pow_of_two(bytes_per_line); + mask = bytes_per_line - 1; + + printed += printer(BINARY_PRINT_DATA_BEGIN, 0, extra, fp); + for (i = 0; i < len; i++) { + if ((i & mask) == 0) { + printed += printer(BINARY_PRINT_LINE_BEGIN, -1, extra, fp); + printed += printer(BINARY_PRINT_ADDR, i, extra, fp); + } + + printed += printer(BINARY_PRINT_NUM_DATA, data[i], extra, fp); + + if (((i & mask) == mask) || i == len - 1) { + for (j = 0; j < mask-(i & mask); j++) + printed += printer(BINARY_PRINT_NUM_PAD, -1, extra, fp); + + printer(BINARY_PRINT_SEP, i, extra, fp); + for (j = i & ~mask; j <= i; j++) + printed += printer(BINARY_PRINT_CHAR_DATA, data[j], extra, fp); + for (j = 0; j < mask-(i & mask); j++) + printed += printer(BINARY_PRINT_CHAR_PAD, i, extra, fp); + printed += printer(BINARY_PRINT_LINE_END, -1, extra, fp); + } + } + printed += printer(BINARY_PRINT_DATA_END, -1, extra, fp); + return printed; +} + +int is_printable_array(char *p, unsigned int len) +{ + unsigned int i; + + if (!p || !len || p[len - 1] != 0) + return 0; + + len--; + + for (i = 0; i < len && p[i]; i++) { + if (!isprint(p[i]) && !isspace(p[i])) + return 0; + } + return 1; +} |
