aboutsummaryrefslogtreecommitdiff
path: root/lib/std/io.zig
AgeCommit message (Collapse)Author
2025-07-11std: rename `io` to `Io` in preparationAndrew Kelley
This commit is non-breaking. std.io is deprecated in favor of std.Io, in preparation for that namespace becoming an interface.
2025-07-07fix 32-bit compilationAndrew Kelley
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-07std.io: move getStdIn, getStdOut, getStdErr functions to fs.FileAndrew Kelley
preparing to rearrange std.io namespace into an interface how to upgrade: std.io.getStdIn() -> std.fs.File.stdin() std.io.getStdOut() -> std.fs.File.stdout() std.io.getStdErr() -> std.fs.File.stderr()
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2025-05-14Revert "Work around stage1 not yet returning null-terminated `@typeInfo` ↵Isaac Freund
strings" This reverts commit c8fa767f083e610840cef688b709783c5ad66acc.
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2025-01-15std.io: remove the "temporary workaround" for stage2_aarch64Andrew Kelley
2024-11-25std.io.Poller: handle EPIPE as EOFAndrew Kelley
closes #17483
2024-10-06std: async read into small temporary buffer between `poll` calls on Windowsmlugg
This commit changes how `std.io.poll` is implemented on Windows. The new implementation unfortunately incurs a little extra system call overhead, but fixes several bugs in the old implementation: * The `lpNumberOfBytesRead` parameter of `ReadFile` was used with overlapped I/O. This is explicitly disallowed by the documentation, as the value written to this pointer is "potentially erroneous"; instead, `GetOverlappedResult` must always be used, even if the operation immediately returns. Documentation states that `lpNumberOfBytesRead` cannot be passed as null on Windows 7, so for compatibility, the parameter is passed as a pointer to a dummy global. * If the initial `ReadFile` returned data, and the next read returned `BROKEN_PIPE`, the received data was silently ignored in the sense that `pollWindows` did not `return`, instead waiting for data to come in on another file (or for all files to close). * The asynchronous `ReadFile` calls which were left pending between calls to `pollWindows` pointed to a potentially unstable buffer, since the user of `poll` may use part of the `LinearFifo` API which rotate its ring buffer. This race condition was causing CI failures in some uses of the compiler server protocol. These issues are all resolved. Now, `pollWindows` will queue an initial read to a small (128-byte) stable buffer per file. When this read is completed, reads directly into the FIFO's writable slice are performed until one is left pending, at which point that read is cancelled (with a check to see if it was completed between the `ReadFile` and `CancelIo` calls) and the next read into the small stable buffer is queued. These small buffer reads are the ones left pending between `pollWindows` calls, avoiding the race condition described above. Related: #21565
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-16Dwarf: rework self-hosted debug info from scratchJacob Young
This is in preparation for incremental and actually being able to debug executables built by the x86_64 backend.
2024-07-15Better implementation of GetLastError. (#20623)Lucas Santos
Instead of calling the dynamically loaded kernel32.GetLastError, we can extract it from the TEB. As shown by [Wine](https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/include/winternl.h#L439), the last error lives at offset 0x34 of the TEB in 32-bit Windows and at offset 0x68 in 64-bit Windows.
2024-05-03add std.zip and support zip files in build.zig.zonJonathan Marler
fixes #17408 Helpful reviewers/testers include Joshe Wolfe, Auguste Rame, Andrew Kelley and Jacob Young. Co-authored-by: Joel Gustafson <joelg@mit.edu>
2024-04-10Uri: propagate per-component encodingJacob Young
This allows `std.Uri.resolve_inplace` to properly preserve the fact that `new` is already escaped but `base` may not be. I originally tried just moving `raw_uri` around, but it made uri resolution unmanagably complicated, so I instead added per-component information to `Uri` which allows extra allocations to be avoided when constructing uris with components from different sources, and in some cases, deferring the work all the way to when the uri is printed, where an allocator may not even be needed. Closes #19587
2024-03-27haiku: fix poll definitionsJacob Young
2024-03-23haiku: debitrotJacob Young
2024-03-21std: promote tests to doctestsAndrew Kelley
Now these show up as "example usage" in generated documentation.
2024-03-20std.io: remove BufferedTeeIgor Anić
Introduced in #19032 as a fix for #18967. Not needed any more after #19253.
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-03-14remove std.io.PeekStreamAndrew Kelley
See #16114. This functionality should be added to bufferedReader instead.
2024-03-11std.builtin: make container layout fields lowercaseTristan Ross
2024-02-25Add pollTimeout for non-blocking/timeout-having pollsSuperAuguste
2024-02-21add BufferedTeeIgor Anić
BufferedTee provides reader interface to the consumer. Data read by consumer is also written to the output. Output is hold lookahead_size bytes behind consumer. Allowing consumer to put back some bytes to be read again. On flush all consumed bytes are flushed to the output. input -> tee -> consumer | output input - underlying unbuffered reader output - writer, receives data read by consumer consumer - uses provided reader interface If lookahead_size is zero output always has same bytes as consumer.
2024-02-09Merge pull request #18712 from Vexu/std.optionsAndrew Kelley
std: make options a struct instance instead of a namespace
2024-02-01remove std.io.ModeVeikka Tuominen
2024-02-01std.start: remove event loop integrationVeikka Tuominen
2024-01-29Add type-erased writer and GenericWriterIan Johnson
This is a companion to #17344 to apply the same change to the `std.io.Writer` interface.
2024-01-22std.io: replace readStructBig with readStructEndianTristan Ross
2024-01-13std.io.GenericReader: add missing error annotationsJacob Young
2024-01-07Work around stage1 not yet returning null-terminated `@typeInfo` stringsCarl Åstholm
These changes can be reverted the next time stage1 is updated.
2023-10-31mem: fix ub in writeIntJacob Young
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
2023-10-27GenericReader error set fixesTravis Staloch
add error.EndOfStream to readEnum() and isBytes() so that users can catch these errors. this also prevents them from panicing with 'invalid error value' on EndOfStream. test both methods.
2023-10-03std: add type-erased reader; base GenericReader on itAndrew Kelley
The idea here is to avoid code bloat by having only one actual io.Reader implementation, which is type erased, and then implement a GenericReader that preserves type information on top of that as thin glue code. The strategy here is for that glue code to `@errSetCast` the result of the type-erased reader functions, however, while trying to do that I ran into #17343.
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13std.io: remove `FindByteOutStream` and `findByteOutStream` (deprecated inEric Joldasov
0.9) Followup to 902df103c6151c257c90de9ba5f29f7f4b9dbea2. Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-24std: Move std.debug.{TTY.Config,detectTTYConfig} to std.io.ttyLinus Groh
Also get rid of the TTY wrapper struct, which was exlusively used as a namespace - this is done by the tty.zig root struct now. detectTTYConfig has been renamed to just detectConfig, which is enough given the new namespace. Additionally, a doc comment had been added.
2023-03-25std: remove temporary workarounds for stage2_x86_64Jacob Young
These seem to work great now.
2023-03-01std.io.poll: remove done functionJonathan Marler
2023-03-01std.io.zig: fmtJonathan Marler
2023-02-28std.io.poll initial windows implementationJonathan Marler
2023-02-27redo std.io.poll with only outputsAndrew Kelley
2023-02-27add std.io.poll and implement it for POSIXAndrew Kelley
I think having inputs is problematic here, it should only be for outputs.
2023-01-11expose std.io.bufferedReaderSizeAndrew Kelley
This allows setting a custom buffer size. In this case I wanted it because using a buffer size large enough to fit a TLS ciphertext record elides a memcpy(). This commit also adds `readAtLeast` to the Reader interface.
2023-01-05std: collect all options under one namespaceVeikka Tuominen
2022-11-05coff: compile and link simple exit program on arm64Jakub Konka
* make image base target dependent * fix relocs to imports
2022-09-07libstd: use windows.GetStdHandle() with stage2_x86_64 backend for nowJakub Konka
2022-04-14stage2: progress towards stage3Andrew Kelley
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly doing element casting for slice element types. This required an enhancement both to stage1 and stage2. * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that abused this is fixed. * Make some parameters comptime to support functions in switch expressions (as opposed to making them function pointers). * Avoid relying on local temporaries being mutable. * Workarounds for when stage1 and stage2 disagree on function pointer types. * Workaround recursive formatting bug with a `@panic("TODO")`. * Remove unreachable `else` prongs for some inferred error sets. All in effort towards #89.