Support binary strings in native printf #12

Open
opened 2026-10-26 03:10:37 +01:00 by erikinkinen · 0 comments
Owner

Problem and motivation

Build helpers need binary strings, including the NUL-separated environment
records already written by the bootloader Cargo helper. Native printf currently
rejects octal escapes and requires the complete result to fit caller workspace.

Proposed behavior and scope

Extend the existing string formatter with %b, the standard single-byte control
escapes and octal byte escapes. Add %c for the first raw operand byte; choose
one NUL for empty or missing character operands without interpreting the rest.
Preserve %s, %%, format repetition and empty missing string operands. Follow the POSIX string-format contract;
document deliberate behavior for unspecified sequences. Support NUL output and
%b cancellation without interpreting operands as commands or format strings.
Use one shared formatter for buffered and native execution. Stream large native
results through caller storage; keep one write when the complete result fits.
Numeric conversions, field widths, precision and full locale support stay outside
this change and remain explicitly documented gaps.

Authority, security and reliability

Use only the authenticated original output/error descriptions. This adds no
filesystem, environment, clock, broker or launch authority. Preflight the complete
reachable format and converted operands before output; reject malformed input
without a prefix write. Keep original message and output backing through
unreturned callbacks, preserve first errors and never replay an uncertain write.

Acceptance criteria

  • Buffered and native paths agree on string and first-byte conversions,
    escape boundaries, format repetition, empty/missing operands and whole-command
    %b cancellation.
  • Native output handles NUL bytes and results larger than caller workspace,
    preserves fitting-result batching and detects malformed input before output.
  • Denied/closed output, failures and unreturned callbacks preserve exact
    original stream identity, backing and once-only cleanup.
  • Guest workflows check binary bytes and statuses with an independent oracle,
    including a NUL-separated build-style record and subsequent ordinary output.
  • The indexed manual, component contracts and technical manual describe the
    supported syntax, deliberate errors and explicit stream authority.

Alternatives and tradeoffs

Imported printf implementations remain useful for unsupported numeric formats.
Sharing one allocation-free formatter avoids maintaining different byte rules in
the buffered model and native command. Caller storage controls chunk size rather
than imposing a product output-length limit.

Tracking and rollout

Coordinate Coreutils PR 2,
Integration PR 12 and the
phase checklist.

## Problem and motivation Build helpers need binary strings, including the NUL-separated environment records already written by the bootloader Cargo helper. Native `printf` currently rejects octal escapes and requires the complete result to fit caller workspace. ## Proposed behavior and scope Extend the existing string formatter with `%b`, the standard single-byte control escapes and octal byte escapes. Add `%c` for the first raw operand byte; choose one NUL for empty or missing character operands without interpreting the rest. Preserve `%s`, `%%`, format repetition and empty missing string operands. Follow the [POSIX string-format contract](https://man7.org/linux/man-pages/man1/printf.1p.html); document deliberate behavior for unspecified sequences. Support NUL output and `%b` cancellation without interpreting operands as commands or format strings. Use one shared formatter for buffered and native execution. Stream large native results through caller storage; keep one write when the complete result fits. Numeric conversions, field widths, precision and full locale support stay outside this change and remain explicitly documented gaps. ## Authority, security and reliability Use only the authenticated original output/error descriptions. This adds no filesystem, environment, clock, broker or launch authority. Preflight the complete reachable format and converted operands before output; reject malformed input without a prefix write. Keep original message and output backing through unreturned callbacks, preserve first errors and never replay an uncertain write. ## Acceptance criteria - [ ] Buffered and native paths agree on string and first-byte conversions, escape boundaries, format repetition, empty/missing operands and whole-command `%b` cancellation. - [ ] Native output handles NUL bytes and results larger than caller workspace, preserves fitting-result batching and detects malformed input before output. - [ ] Denied/closed output, failures and unreturned callbacks preserve exact original stream identity, backing and once-only cleanup. - [ ] Guest workflows check binary bytes and statuses with an independent oracle, including a NUL-separated build-style record and subsequent ordinary output. - [ ] The indexed manual, component contracts and technical manual describe the supported syntax, deliberate errors and explicit stream authority. ## Alternatives and tradeoffs Imported printf implementations remain useful for unsupported numeric formats. Sharing one allocation-free formatter avoids maintaining different byte rules in the buffered model and native command. Caller storage controls chunk size rather than imposing a product output-length limit. ## Tracking and rollout Coordinate [Coreutils PR 2](https://git.erikinkinen.fi/erix/coreutils/pulls/2), [Integration PR 12](https://git.erikinkinen.fi/erix/integration/pulls/12) and the [phase checklist](https://git.erikinkinen.fi/erix/integration/issues/65).
erikinkinen added this to the Alpha 1 milestone 2026-10-30 09:33:36 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
erix/coreutils#12
No description provided.