PosixUnistd
Performs one raw POSIX descriptor write.
Module std.posix.unistd
import std.posix.unistd;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
<
pub fn<.C> write(
FileDescriptor: i32,
[abi.NoCapture] Buffer: readonly byte*,
Count: usize
) -> isize;Performs one raw POSIX descriptor write.
This declaration exposes host write directly. It may block, mutate the descriptor offset and external state, return a positive short count, and set thread-local errno on failure. A closed pipe or socket may deliver SIGPIPE before a negative result becomes observable; canonical std.io uses the scoped internal platform helper instead.
FileDescriptor: Any target POSIX descriptor value. Invalid or unsuitable values produce an ordinary negative failure result. Buffer: Borrowed first byte of the range to read. Count: Maximum number of bytes to read from Buffer. Return: A count from zero through Count, or a negative failure value. Pre: Safety: when Count is positive, Buffer is nonnull and has valid provenance for a live byte-aligned readable range of at least Count bytes; when Count is zero, the pointer may be null and is not accessed. Pre: Safety: the complete range remains live and free of conflicting concurrent mutation until return and is neither written nor retained. Pre: Safety: the target uses the declared int/size_t/ssize_t C ABI, descriptor runtime state is available, and no foreign unwind crosses into Sn. Warning: Performs no retry, grants no atomic-write guarantee, and may terminate through the host SIGPIPE disposition.
Example
module example.write;
from std.posix.unistd import write;
fn Main() -> i32 {
unsafe {
let Written: isize = write(1, c"x", 1);
if Written < 0 {
return 1;
}
}
return 0;
}