mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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
50 lines
2.0 KiB
Zig
50 lines
2.0 KiB
Zig
const std = @import("../std.zig");
|
|
const fd_t = std.c.fd_t;
|
|
const off_t = std.c.off_t;
|
|
const unexpectedErrno = std.posix.unexpectedErrno;
|
|
const errno = std.posix.errno;
|
|
|
|
pub const CopyFileRangeError = error{
|
|
/// If infd is not open for reading or outfd is not open for writing, or
|
|
/// opened for writing with O_APPEND, or if infd and outfd refer to the
|
|
/// same file.
|
|
BadFileFlags,
|
|
/// If the copy exceeds the process's file size limit or the maximum
|
|
/// file size for the file system outfd re- sides on.
|
|
FileTooBig,
|
|
/// A signal interrupted the system call before it could be completed.
|
|
/// This may happen for files on some NFS mounts. When this happens,
|
|
/// the values pointed to by inoffp and outoffp are reset to the
|
|
/// initial values for the system call.
|
|
Interrupted,
|
|
/// One of:
|
|
/// * infd and outfd refer to the same file and the byte ranges overlap.
|
|
/// * The flags argument is not zero.
|
|
/// * Either infd or outfd refers to a file object that is not a regular file.
|
|
InvalidArguments,
|
|
/// An I/O error occurred while reading/writing the files.
|
|
InputOutput,
|
|
/// Corrupted data was detected while reading from a file system.
|
|
CorruptedData,
|
|
/// Either infd or outfd refers to a directory.
|
|
IsDir,
|
|
/// File system that stores outfd is full.
|
|
NoSpaceLeft,
|
|
};
|
|
|
|
pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, len: usize, flags: u32) CopyFileRangeError!usize {
|
|
const rc = std.c.copy_file_range(fd_in, off_in, fd_out, off_out, len, flags);
|
|
switch (errno(rc)) {
|
|
.SUCCESS => return @intCast(rc),
|
|
.BADF => return error.BadFileFlags,
|
|
.FBIG => return error.FileTooBig,
|
|
.INTR => return error.Interrupted,
|
|
.INVAL => return error.InvalidArguments,
|
|
.IO => return error.InputOutput,
|
|
.INTEGRITY => return error.CorruptedData,
|
|
.ISDIR => return error.IsDir,
|
|
.NOSPC => return error.NoSpaceLeft,
|
|
else => |err| return unexpectedErrno(err),
|
|
}
|
|
}
|