fcoreutils 0.22.0

High-performance GNU coreutils replacement with SIMD and parallelism
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
// fod -- octal/hex dump
//
// Usage: od [OPTION]... [FILE]...
//        od [-abcdfilosx] [FILE] [[+]OFFSET[.][b]]

use std::io::{self, Read};
use std::process;

use coreutils_rs::common::reset_sigpipe;
use coreutils_rs::od::{
    AddressRadix, Endian, OdConfig, OutputFormat, od_process, parse_format_type,
};

const TOOL_NAME: &str = "od";
const VERSION: &str = env!("CARGO_PKG_VERSION");

fn main() {
    reset_sigpipe();

    let args: Vec<String> = std::env::args().skip(1).collect();

    let mut address_radix = None;
    let mut formats: Vec<OutputFormat> = Vec::new();
    let mut z_flags: Vec<bool> = Vec::new();
    let mut skip_bytes: u64 = 0;
    let mut read_bytes: Option<u64> = None;
    let mut width: Option<usize> = None;
    let mut show_duplicates = false;
    let mut endian = Endian::Native;
    let mut operands: Vec<String> = Vec::new();
    let mut saw_dashdash = false;

    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];
        if saw_dashdash {
            operands.push(arg.clone());
            i += 1;
            continue;
        }
        match arg.as_str() {
            "--help" => {
                print_help();
                return;
            }
            "--version" => {
                println!("{} (fcoreutils) {}", TOOL_NAME, VERSION);
                return;
            }
            "--" => saw_dashdash = true,
            "-v" | "--output-duplicates" => show_duplicates = true,

            "--traditional" => { /* accepted, ignored */ }

            _ if arg.starts_with("--endian=") => {
                let val = &arg["--endian=".len()..];
                match val {
                    "little" => endian = Endian::Little,
                    "big" => endian = Endian::Big,
                    _ => {
                        eprintln!(
                            "{}: invalid argument '{}' for '--endian'\nValid arguments are:\n  - 'big'\n  - 'little'",
                            TOOL_NAME, val
                        );
                        process::exit(1);
                    }
                }
            }

            // Traditional format shortcuts
            "-a" => {
                formats.push(OutputFormat::NamedChar);
                z_flags.push(false);
            }
            "-b" => {
                formats.push(OutputFormat::Octal(1));
                z_flags.push(false);
            }
            "-c" => {
                formats.push(OutputFormat::PrintableChar);
                z_flags.push(false);
            }
            "-d" => {
                formats.push(OutputFormat::UnsignedDec(2));
                z_flags.push(false);
            }
            "-e" => {
                formats.push(OutputFormat::Float(8));
                z_flags.push(false);
            }
            "-f" => {
                formats.push(OutputFormat::Float(4));
                z_flags.push(false);
            }
            "-h" => {
                formats.push(OutputFormat::Hex(2));
                z_flags.push(false);
            }
            "-i" => {
                formats.push(OutputFormat::SignedDec(4));
                z_flags.push(false);
            }
            "-l" => {
                formats.push(OutputFormat::SignedDec(8));
                z_flags.push(false);
            }
            "-o" => {
                formats.push(OutputFormat::Octal(2));
                z_flags.push(false);
            }
            "-s" => {
                formats.push(OutputFormat::SignedDec(2));
                z_flags.push(false);
            }
            "-x" => {
                formats.push(OutputFormat::Hex(2));
                z_flags.push(false);
            }

            _ if arg.starts_with("--address-radix=") => {
                address_radix = Some(parse_radix(&arg["--address-radix=".len()..]));
            }
            _ if arg.starts_with("--format=") => {
                let fmt_str = &arg["--format=".len()..];
                match parse_format_type(fmt_str) {
                    Ok((f, z)) => {
                        formats.push(f);
                        z_flags.push(z);
                    }
                    Err(e) => {
                        eprintln!("{}: {}", TOOL_NAME, e);
                        process::exit(1);
                    }
                }
            }
            _ if arg.starts_with("--skip-bytes=") => {
                skip_bytes = parse_offset(&arg["--skip-bytes=".len()..]);
            }
            _ if arg.starts_with("--read-bytes=") => {
                read_bytes = Some(parse_offset(&arg["--read-bytes=".len()..]));
            }
            _ if arg == "--width" => {
                // --width without =
                i += 1;
                if i < args.len() {
                    width = Some(args[i].parse().unwrap_or(16));
                }
            }
            _ if arg.starts_with("--width=") => {
                width = Some(arg["--width=".len()..].parse().unwrap_or(16));
            }
            _ if arg.starts_with("--width") => {
                // --width with no argument means default 32
                width = Some(32);
            }
            _ if arg.starts_with('-') && arg.len() > 1 && !arg.starts_with("--") => {
                // Short options
                let bytes = arg.as_bytes();
                let mut j = 1;
                while j < bytes.len() {
                    match bytes[j] {
                        b'A' => {
                            j += 1;
                            if j < bytes.len() {
                                address_radix =
                                    Some(parse_radix(&String::from_utf8_lossy(&bytes[j..j + 1])));
                                j += 1;
                            } else {
                                i += 1;
                                if i < args.len() {
                                    address_radix = Some(parse_radix(&args[i]));
                                }
                            }
                            continue;
                        }
                        b'j' => {
                            let rest: String =
                                String::from_utf8_lossy(&bytes[j + 1..]).into_owned();
                            if rest.is_empty() {
                                i += 1;
                                if i < args.len() {
                                    skip_bytes = parse_offset(&args[i]);
                                }
                            } else {
                                skip_bytes = parse_offset(&rest);
                            }
                            j = bytes.len(); // consumed rest
                            continue;
                        }
                        b'N' => {
                            let rest: String =
                                String::from_utf8_lossy(&bytes[j + 1..]).into_owned();
                            if rest.is_empty() {
                                i += 1;
                                if i < args.len() {
                                    read_bytes = Some(parse_offset(&args[i]));
                                }
                            } else {
                                read_bytes = Some(parse_offset(&rest));
                            }
                            j = bytes.len();
                            continue;
                        }
                        b't' => {
                            let rest: String =
                                String::from_utf8_lossy(&bytes[j + 1..]).into_owned();
                            let fmt_str = if rest.is_empty() {
                                i += 1;
                                if i < args.len() {
                                    args[i].clone()
                                } else {
                                    eprintln!("{}: option requires an argument -- 't'", TOOL_NAME);
                                    process::exit(1);
                                }
                            } else {
                                rest
                            };
                            match parse_format_type(&fmt_str) {
                                Ok((f, z)) => {
                                    formats.push(f);
                                    z_flags.push(z);
                                }
                                Err(e) => {
                                    eprintln!("{}: {}", TOOL_NAME, e);
                                    process::exit(1);
                                }
                            }
                            j = bytes.len();
                            continue;
                        }
                        b'w' => {
                            let rest: String =
                                String::from_utf8_lossy(&bytes[j + 1..]).into_owned();
                            if rest.is_empty() {
                                // -w alone means default 32
                                width = Some(32);
                            } else {
                                width = Some(rest.parse().unwrap_or(16));
                            }
                            j = bytes.len();
                            continue;
                        }
                        b'v' => show_duplicates = true,
                        b'a' => {
                            formats.push(OutputFormat::NamedChar);
                            z_flags.push(false);
                        }
                        b'b' => {
                            formats.push(OutputFormat::Octal(1));
                            z_flags.push(false);
                        }
                        b'c' => {
                            formats.push(OutputFormat::PrintableChar);
                            z_flags.push(false);
                        }
                        b'd' => {
                            formats.push(OutputFormat::UnsignedDec(2));
                            z_flags.push(false);
                        }
                        b'e' => {
                            formats.push(OutputFormat::Float(8));
                            z_flags.push(false);
                        }
                        b'f' => {
                            formats.push(OutputFormat::Float(4));
                            z_flags.push(false);
                        }
                        b'h' => {
                            formats.push(OutputFormat::Hex(2));
                            z_flags.push(false);
                        }
                        b'i' => {
                            formats.push(OutputFormat::SignedDec(4));
                            z_flags.push(false);
                        }
                        b'l' => {
                            formats.push(OutputFormat::SignedDec(8));
                            z_flags.push(false);
                        }
                        b'o' => {
                            formats.push(OutputFormat::Octal(2));
                            z_flags.push(false);
                        }
                        b's' => {
                            formats.push(OutputFormat::SignedDec(2));
                            z_flags.push(false);
                        }
                        b'x' => {
                            formats.push(OutputFormat::Hex(2));
                            z_flags.push(false);
                        }
                        _ => {
                            eprintln!("{}: invalid option -- '{}'", TOOL_NAME, bytes[j] as char);
                            eprintln!("Try '{} --help' for more information.", TOOL_NAME);
                            process::exit(1);
                        }
                    }
                    j += 1;
                }
            }
            _ if arg.starts_with("--") => {
                eprintln!("{}: unrecognized option '{}'", TOOL_NAME, arg);
                eprintln!("Try '{} --help' for more information.", TOOL_NAME);
                process::exit(1);
            }
            _ if arg.starts_with('+') => {
                // Traditional offset: +OFFSET[.][b]
                skip_bytes = parse_offset(&arg[1..]);
            }
            _ => operands.push(arg.clone()),
        }
        i += 1;
    }

    let config = OdConfig {
        address_radix: address_radix.unwrap_or(AddressRadix::Octal),
        formats: if formats.is_empty() {
            vec![OutputFormat::Octal(2)]
        } else {
            formats
        },
        z_flags: if z_flags.is_empty() {
            vec![false]
        } else {
            z_flags
        },
        skip_bytes,
        read_bytes,
        width: width.unwrap_or(16),
        show_duplicates,
        endian,
    };

    let stdout = io::stdout();
    let mut out = io::BufWriter::with_capacity(256 * 1024, stdout.lock());

    if operands.is_empty() || (operands.len() == 1 && operands[0] == "-") {
        // On Unix, use unbuffered stdin reads when -N is specified so that
        // sequential invocations like `(od -N3 -c; od -N3 -c) < file` work
        // correctly — buffered StdinLock would over-read from the fd.
        let result = {
            #[cfg(unix)]
            {
                use std::os::unix::io::FromRawFd;
                if config.read_bytes.is_some() {
                    // SAFETY: fd 0 (stdin) is always valid in normal process execution.
                    // ManuallyDrop prevents closing fd 0 on drop. Using &File gives
                    // direct unbuffered read(2) so exactly read_bytes bytes are consumed.
                    let stdin_file =
                        std::mem::ManuallyDrop::new(unsafe { std::fs::File::from_raw_fd(0) });
                    od_process(&*stdin_file, &mut out, &config)
                } else {
                    let stdin = io::stdin();
                    od_process(stdin.lock(), &mut out, &config)
                }
            }
            #[cfg(not(unix))]
            {
                let stdin = io::stdin();
                od_process(stdin.lock(), &mut out, &config)
            }
        };
        if let Err(e) = result {
            eprintln!("{}: {}", TOOL_NAME, e);
            process::exit(1);
        }
    } else if operands.len() == 1 && operands[0] != "-" {
        match coreutils_rs::common::io::read_file_with_hints(
            std::path::Path::new(&operands[0]),
            coreutils_rs::common::io::MmapHints::Lazy,
        ) {
            Ok(data) => {
                if let Err(e) = od_process(data.as_ref(), &mut out, &config) {
                    eprintln!("{}: {}", TOOL_NAME, e);
                    process::exit(1);
                }
            }
            Err(e) => {
                eprintln!("{}: {}: {}", TOOL_NAME, operands[0], e);
                process::exit(1);
            }
        }
    } else {
        // Multiple files: concatenate via std::fs::read (avoids mmap overhead since data
        // is immediately copied into combined buffer anyway).
        let mut combined = Vec::new();
        for path in &operands {
            if path == "-" {
                let mut buf = Vec::new();
                io::stdin()
                    .lock()
                    .read_to_end(&mut buf)
                    .unwrap_or_else(|e| {
                        eprintln!("{}: standard input: {}", TOOL_NAME, e);
                        process::exit(1);
                    });
                combined.extend_from_slice(&buf);
            } else {
                match std::fs::read(path) {
                    Ok(data) => {
                        combined.extend_from_slice(&data);
                    }
                    Err(e) => {
                        eprintln!("{}: {}: {}", TOOL_NAME, path, e);
                        process::exit(1);
                    }
                }
            }
        }
        if let Err(e) = od_process(combined.as_slice(), &mut out, &config) {
            eprintln!("{}: {}", TOOL_NAME, e);
            process::exit(1);
        }
    }
}

fn parse_radix(s: &str) -> AddressRadix {
    match s {
        "o" => AddressRadix::Octal,
        "d" => AddressRadix::Decimal,
        "x" => AddressRadix::Hex,
        "n" => AddressRadix::None,
        _ => {
            eprintln!(
                "{}: invalid address radix '{}'; it must be one character from [doxn]",
                TOOL_NAME, s
            );
            process::exit(1);
        }
    }
}

fn parse_offset(s: &str) -> u64 {
    let s = s.trim();
    let (num_str, multiplier) = if let Some(n) = s.strip_suffix("GiB") {
        (n, 1_073_741_824u64)
    } else if let Some(n) = s.strip_suffix("GB") {
        (n, 1_000_000_000u64)
    } else if let Some(n) = s.strip_suffix('G') {
        (n, 1_073_741_824u64)
    } else if let Some(n) = s.strip_suffix("MiB") {
        (n, 1_048_576u64)
    } else if let Some(n) = s.strip_suffix("MB") {
        (n, 1_000_000u64)
    } else if let Some(n) = s.strip_suffix('M') {
        (n, 1_048_576u64)
    } else if let Some(n) = s.strip_suffix("KiB") {
        (n, 1_024u64)
    } else if let Some(n) = s.strip_suffix("KB") {
        (n, 1_000u64)
    } else if let Some(n) = s.strip_suffix("kB") {
        (n, 1_000u64)
    } else if let Some(n) = s.strip_suffix('K') {
        (n, 1_024u64)
    } else if let Some(n) = s.strip_suffix('k') {
        (n, 1_024u64)
    } else if let Some(n) = s.strip_suffix('b') {
        (n, 512u64)
    } else {
        (s, 1u64)
    };

    let base_val = if num_str.starts_with("0x") || num_str.starts_with("0X") {
        u64::from_str_radix(&num_str[2..], 16).unwrap_or(0)
    } else if num_str.starts_with('0') && num_str.len() > 1 {
        u64::from_str_radix(&num_str[1..], 8).unwrap_or(0)
    } else {
        num_str.parse::<u64>().unwrap_or(0)
    };

    base_val * multiplier
}

fn print_help() {
    println!("Usage: {} [OPTION]... [FILE]...", TOOL_NAME);
    println!("  or:  {} -C [OPTION]... [FILE]...", TOOL_NAME);
    println!("Write an unambiguous representation, octal bytes by default,");
    println!("of FILE to standard output.");
    println!();
    println!("  -A, --address-radix=RADIX   output format for file offsets; RADIX is one");
    println!("                                of [doxn], for Decimal, Octal, Hex or None");
    println!("  -j, --skip-bytes=BYTES      skip BYTES input bytes first");
    println!("  -N, --read-bytes=BYTES      limit dump to BYTES input bytes");
    println!("  -t, --format=TYPE           select output format or formats");
    println!("  -v, --output-duplicates     do not use * to mark line suppression");
    println!("  -w[BYTES], --width[=BYTES]  output BYTES bytes per output line;");
    println!("                                32 is implied when BYTES is not specified");
    println!("      --help     display this help and exit");
    println!("      --version  output version information and exit");
    println!();
    println!("Traditional format specifications may be intermixed:");
    println!("  -b   same as -t o1");
    println!("  -c   same as -t c");
    println!("  -d   same as -t u2");
    println!("  -o   same as -t o2");
    println!("  -s   same as -t d2");
    println!("  -x   same as -t x2");
}

#[cfg(test)]
mod tests {
    use std::io::Write;
    use std::process::Command;
    use std::process::Stdio;

    fn cmd() -> Command {
        let mut path = std::env::current_exe().unwrap();
        path.pop();
        path.pop();
        path.push("fod");
        Command::new(path)
    }
    #[cfg(unix)]
    #[test]
    fn test_od_basic() {
        let mut child = cmd()
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"AB").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("0000000"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_hex_format() {
        let mut child = cmd()
            .args(["-t", "x1"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"AB").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("41") && stdout.contains("42"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_char_format() {
        let mut child = cmd()
            .arg("-c")
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"Hi\n").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("H") && stdout.contains("i") && stdout.contains("\\n"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_empty_input() {
        let mut child = cmd()
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        drop(child.stdin.take().unwrap());
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("0000000"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_file() {
        let dir = tempfile::tempdir().unwrap();
        let file = dir.path().join("test.bin");
        std::fs::write(&file, [0x41, 0x42, 0x43]).unwrap();
        let output = cmd().arg(file.to_str().unwrap()).output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("0000000"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_byte_count() {
        let mut child = cmd()
            .args(["-N", "2"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"ABCDEF").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        // Only 2 bytes read, so final offset should be 0000002
        assert!(stdout.contains("0000002"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_skip_bytes() {
        let mut child = cmd()
            .args(["-j", "2", "-t", "x1"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"ABCDEF").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        // Skip 2 bytes, should start with C (0x43)
        assert!(stdout.contains("43"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_octal_shorthand() {
        let mut child = cmd()
            .arg("-b")
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"A").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        // 'A' = 0101 in octal
        assert!(stdout.contains("101"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_hex_shorthand() {
        let mut child = cmd()
            .arg("-x")
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"AB").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
    }

    #[cfg(unix)]
    #[test]
    fn test_od_nonexistent_file() {
        let output = cmd().arg("/nonexistent_xyz_od").output().unwrap();
        assert!(!output.status.success());
    }

    #[cfg(unix)]
    #[test]
    fn test_od_binary_data() {
        let mut child = cmd()
            .args(["-t", "x1"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child
            .stdin
            .take()
            .unwrap()
            .write_all(&[0x00, 0xFF, 0x7F, 0x80])
            .unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        assert!(stdout.contains("00") && stdout.contains("ff"));
    }

    #[cfg(unix)]
    #[test]
    fn test_od_address_radix() {
        let mut child = cmd()
            .args(["-A", "x"])
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        child.stdin.take().unwrap().write_all(b"A").unwrap();
        let output = child.wait_with_output().unwrap();
        assert!(output.status.success());
        let stdout = String::from_utf8_lossy(&output.stdout);
        // Hex address radix
        assert!(stdout.contains("000000"));
    }
}