Function createFile [src]
Creates, opens, or overwrites a file with write access.
Call File.close on the result when done.
Asserts that the path parameter has no null bytes.
On Windows, sub_path should be encoded as WTF-8.
On WASI, sub_path should be encoded as valid UTF-8.
On other platforms, sub_path is an opaque sequence of bytes with no particular encoding.
Prototype
pub fn createFile(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File
Parameters
self: Dir
sub_path: []const u8
flags: File.CreateFlags
Source
pub fn createFile(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
if (native_os == .windows) {
const path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
return self.createFileW(path_w.span(), flags);
}
if (native_os == .wasi) {
return .{
.handle = try posix.openatWasi(self.fd, sub_path, .{}, .{
.CREAT = true,
.TRUNC = flags.truncate,
.EXCL = flags.exclusive,
}, .{}, .{
.FD_READ = flags.read,
.FD_WRITE = true,
.FD_DATASYNC = true,
.FD_SEEK = true,
.FD_TELL = true,
.FD_FDSTAT_SET_FLAGS = true,
.FD_SYNC = true,
.FD_ALLOCATE = true,
.FD_ADVISE = true,
.FD_FILESTAT_SET_TIMES = true,
.FD_FILESTAT_SET_SIZE = true,
.FD_FILESTAT_GET = true,
// POLL_FD_READWRITE only grants extra rights if the corresponding FD_READ and/or
// FD_WRITE is also set.
.POLL_FD_READWRITE = true,
}, .{}),
};
}
const path_c = try posix.toPosixPath(sub_path);
return self.createFileZ(&path_c, flags);
}