One commit, because the parts below only build together. Allocator: an interval needed at the current instruction is never evicted, and the allocated-program verifier checks that every operand sits where the allocation says. AArch64 encoder: compiler_aarch64.zi encodes allocated machine IR with the shared ARM byte helpers, maps the function-address relocation, sign-extends signed 8- and 16-bit loads and rejects what it cannot encode with a named diagnostic. It has no AOT ELF writer yet. Native default with checked pointers and no fallback: on linux-x86_64, `ziran run app.zx`, `zi2zx run`, the embedding API's Auto and the Kryon players run a bundle's verified program as native code in W^X memory. Stray and freed pointers, double free, bounds and read-only stores trap. A native gap is a named preflight error, nothing falls back to the engine, and `--backend engine` picks it explicitly. zx2native uses the same preflight. Native code exchanges module state for hot reload, checks the stack, zeroes fresh locals, spends fuel at the engine's checkpoints and returns records, arrays and strings from host calls. `zi2zx --debug` source origins name lines in native traps and `zx2native --emit map`. The host value API drops its VM prefix (HostValue, HOST_*). A call with a record result loads the hidden result address into rax only after its stack arguments are stored, and an indirect target stays in r10: rax could hold a stack argument (Kryon's text-field clip guard arrived as an address) or the target (indirect calls returning records crashed). Self-hosting ports: compiler_backend_process, compiler_backend_cache, compiler_native_names and compiler_runtime_emit replace the zir_c_build, zir_c_cache and zir_c_process C, with checked bootstrap C and Makefile rules. zir_c.toolchain again reports "compiling OUT failed:" with the head of the compiler output and a truncation marker. The parallel scheduler no longer stalls on a held compiler after reaping a finished job, and poll or read errors now fail the build. A fresh BUILD_DIR (Kryon's runtime build) builds: generated files have pattern rules, objects wait for the headers they include, and engine flags are per object instead of leaking into zi2c. Legacy removals F1-F10 and N1-N4: the duplicate LirX64 encoder and its spec test, zir_c_*, zir_runtime and zir_native, nine zero-reference spec tests, vec_capacity, the zx_metadata and native_cache_names benchmarks, build-android-host.sh and two shell wrappers are deleted; zx2native is machine-only; `zi2zx` rejects `--opt` on ZX input; the bootstrap is regenerated. ASSEMBLY docs, the legacy-removal plan, the milestones and the remaining-work plan record the current position. Co-Authored-By: Claude Opus 5.5 <[email protected]>
665 lines
21 KiB
C
665 lines
21 KiB
C
/* Generated by zi2c from file_linux.zi. */
|
|
#include <stdbool.h>
|
|
#include "zir_string_types.h"
|
|
#include "zir_bounds.h"
|
|
#define ZIRAN_FILE_LINUX_H_PRIVATE 1
|
|
#include "file_linux.h"
|
|
#undef ZIRAN_FILE_LINUX_H_PRIVATE
|
|
#include "c_string.h"
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadLinkRaw_133b334a
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadLinkRaw_133b334a
|
|
#ifdef __APPLE__
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity) __asm__("_readlink");
|
|
#else
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity) __asm__("readlink");
|
|
#endif
|
|
static ptrdiff_t
|
|
zir_f_76512f487eef232a_ReadLinkRaw(uint8_t* path, uint8_t* output, size_t capacity)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_ReadLinkRaw(path, output, capacity);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_OpenRaw_e4db28c4
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_OpenRaw_e4db28c4
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("_open");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_OpenRaw(uint8_t* path, int32_t flags, ...) __asm__("open");
|
|
#endif
|
|
#define zir_f_76512f487eef232a_OpenRaw zir_foreign_zir_f_76512f487eef232a_OpenRaw
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_CloseRaw_d6ec0c1e
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_CloseRaw_d6ec0c1e
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_CloseRaw(int32_t fd) __asm__("_close");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_CloseRaw(int32_t fd) __asm__("close");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_CloseRaw(int32_t fd)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_CloseRaw(fd);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadRaw_bf7cf6fc
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadRaw_bf7cf6fc
|
|
#ifdef __APPLE__
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("_read");
|
|
#else
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count) __asm__("read");
|
|
#endif
|
|
static ptrdiff_t
|
|
zir_f_76512f487eef232a_ReadRaw(int32_t fd, uint8_t* output, size_t count)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_ReadRaw(fd, output, count);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_WriteRaw_06f26813
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_WriteRaw_06f26813
|
|
#ifdef __APPLE__
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("_write");
|
|
#else
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count) __asm__("write");
|
|
#endif
|
|
static ptrdiff_t
|
|
zir_f_76512f487eef232a_WriteRaw(int32_t fd, uint8_t* input, size_t count)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_WriteRaw(fd, input, count);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_OpenDirectoryRaw_5c49cc32
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_OpenDirectoryRaw_5c49cc32
|
|
#ifdef __APPLE__
|
|
void* zir_foreign_zir_f_76512f487eef232a_OpenDirectoryRaw(uint8_t* path) __asm__("_opendir");
|
|
#else
|
|
void* zir_foreign_zir_f_76512f487eef232a_OpenDirectoryRaw(uint8_t* path) __asm__("opendir");
|
|
#endif
|
|
static void*
|
|
zir_f_76512f487eef232a_OpenDirectoryRaw(uint8_t* path)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_OpenDirectoryRaw(path);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadDirectoryRaw_58424481
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadDirectoryRaw_58424481
|
|
#ifdef __APPLE__
|
|
DirectoryMetadata* zir_foreign_zir_f_76512f487eef232a_ReadDirectoryRaw(void* directory) __asm__("_readdir64");
|
|
#else
|
|
DirectoryMetadata* zir_foreign_zir_f_76512f487eef232a_ReadDirectoryRaw(void* directory) __asm__("readdir64");
|
|
#endif
|
|
static DirectoryMetadata*
|
|
zir_f_76512f487eef232a_ReadDirectoryRaw(void* directory)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_ReadDirectoryRaw(directory);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_CloseDirectoryRaw_cec46a14
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_CloseDirectoryRaw_cec46a14
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_CloseDirectoryRaw(void* directory) __asm__("_closedir");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_CloseDirectoryRaw(void* directory) __asm__("closedir");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_CloseDirectoryRaw(void* directory)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_CloseDirectoryRaw(directory);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_DirectoryErrno_40ae2072
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_DirectoryErrno_40ae2072
|
|
#ifdef __APPLE__
|
|
int32_t* zir_foreign_zir_f_76512f487eef232a_DirectoryErrno(void) __asm__("___errno_location");
|
|
#else
|
|
int32_t* zir_foreign_zir_f_76512f487eef232a_DirectoryErrno(void) __asm__("__errno_location");
|
|
#endif
|
|
static int32_t*
|
|
zir_f_76512f487eef232a_DirectoryErrno(void)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_DirectoryErrno();
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_SeekRaw_6ab0c034
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_SeekRaw_6ab0c034
|
|
#ifdef __APPLE__
|
|
int64_t zir_foreign_zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin) __asm__("_lseek");
|
|
#else
|
|
int64_t zir_foreign_zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin) __asm__("lseek");
|
|
#endif
|
|
static int64_t
|
|
zir_f_76512f487eef232a_SeekRaw(int32_t fd, int64_t offset, int32_t origin)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_SeekRaw(fd, offset, origin);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_ReadAtRaw_c0d26f21
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_ReadAtRaw_c0d26f21
|
|
#ifdef __APPLE__
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset) __asm__("_pread");
|
|
#else
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset) __asm__("pread");
|
|
#endif
|
|
static ptrdiff_t
|
|
zir_f_76512f487eef232a_ReadAtRaw(int32_t fd, uint8_t* output, size_t count, int64_t offset)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_ReadAtRaw(fd, output, count, offset);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_WriteAtRaw_b81fa0e4
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_WriteAtRaw_b81fa0e4
|
|
#ifdef __APPLE__
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset) __asm__("_pwrite");
|
|
#else
|
|
ptrdiff_t zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset) __asm__("pwrite");
|
|
#endif
|
|
static ptrdiff_t
|
|
zir_f_76512f487eef232a_WriteAtRaw(int32_t fd, uint8_t* input, size_t count, int64_t offset)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_WriteAtRaw(fd, input, count, offset);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_MakeDirectoryRaw_a57b07a1
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_MakeDirectoryRaw_a57b07a1
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode) __asm__("_mkdir");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode) __asm__("mkdir");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_MakeDirectoryRaw(uint8_t* path, int32_t mode)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_MakeDirectoryRaw(path, mode);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_UnlinkRaw_1f92ad9b
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_UnlinkRaw_1f92ad9b
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path) __asm__("_unlink");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path) __asm__("unlink");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_UnlinkRaw(uint8_t* path)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_UnlinkRaw(path);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_LinkRaw_7acc0972
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_LinkRaw_7acc0972
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination) __asm__("_link");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination) __asm__("link");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_LinkRaw(uint8_t* source, uint8_t* destination)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_LinkRaw(source, destination);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAtRaw_57868d39
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAtRaw_57868d39
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination) __asm__("_renameat");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination) __asm__("renameat");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_RenameAtRaw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_RenameAtRaw(old_directory, source,
|
|
new_directory, destination);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAt2Raw_6fa9efde
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_RenameAt2Raw_6fa9efde
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags) __asm__("_renameat2");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags) __asm__("renameat2");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_RenameAt2Raw(int32_t old_directory, uint8_t* source, int32_t new_directory, uint8_t* destination, uint32_t flags)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_RenameAt2Raw(old_directory, source,
|
|
new_directory, destination, flags);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_76512f487eef232a_SyncRaw_6212288d
|
|
#define ZIR_FOREIGN_zir_f_76512f487eef232a_SyncRaw_6212288d
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_SyncRaw(int32_t fd) __asm__("_fsync");
|
|
#else
|
|
int32_t zir_foreign_zir_f_76512f487eef232a_SyncRaw(int32_t fd) __asm__("fsync");
|
|
#endif
|
|
static int32_t
|
|
zir_f_76512f487eef232a_SyncRaw(int32_t fd)
|
|
{
|
|
return zir_foreign_zir_f_76512f487eef232a_SyncRaw(fd);
|
|
}
|
|
#endif
|
|
#ifndef ZIRAN_MAYBE_UNUSED
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
|
|
#else
|
|
#define ZIRAN_MAYBE_UNUSED
|
|
#endif
|
|
#endif
|
|
static int32_t file_linux_OpenPath(uint8_t* path, int32_t flags, int32_t mode) ZIRAN_MAYBE_UNUSED;
|
|
static FileHandle file_linux_OpenWithFlags(String path, int32_t flags) ZIRAN_MAYBE_UNUSED;
|
|
|
|
static int32_t
|
|
file_linux_OpenPath(uint8_t* path, int32_t flags, int32_t mode)
|
|
{
|
|
return zir_f_76512f487eef232a_OpenRaw(path, flags, mode);
|
|
}
|
|
|
|
static FileHandle
|
|
file_linux_OpenWithFlags(String path, int32_t flags)
|
|
{
|
|
FileHandle result = {0};
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return result;
|
|
}
|
|
int32_t* value_2 = &(result.fd);
|
|
(*value_2) = file_linux_OpenPath(&(name[0]), flags, 420);
|
|
bool* value_3 = &(result.valid);
|
|
(*value_3) = result.fd >= 0;
|
|
return result;
|
|
}
|
|
|
|
FileHandle
|
|
OpenRead(String path)
|
|
{
|
|
return file_linux_OpenWithFlags(path, 0);
|
|
}
|
|
|
|
FileHandle
|
|
OpenUpdate(String path)
|
|
{
|
|
return file_linux_OpenWithFlags(path, 66);
|
|
}
|
|
|
|
FileHandle
|
|
OpenWrite(String path)
|
|
{
|
|
return file_linux_OpenWithFlags(path, 1);
|
|
}
|
|
|
|
FileHandle
|
|
OpenReplace(String path)
|
|
{
|
|
return file_linux_OpenWithFlags(path, 577);
|
|
}
|
|
|
|
FileHandle
|
|
OpenNew(String path)
|
|
{
|
|
return file_linux_OpenWithFlags(path, 193);
|
|
}
|
|
|
|
FileHandle
|
|
OpenExclusivePrivate(String path)
|
|
{
|
|
FileHandle result = {0};
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return result;
|
|
}
|
|
int32_t* value_2 = &(result.fd);
|
|
(*value_2) = file_linux_OpenPath(&(name[0]), 193, 384);
|
|
bool* value_3 = &(result.valid);
|
|
(*value_3) = result.fd >= 0;
|
|
return result;
|
|
}
|
|
|
|
bool
|
|
RemoveFile(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_UnlinkRaw(&(name[0])) == 0;
|
|
}
|
|
|
|
bool
|
|
PathIsLink(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
uint8_t byte = 0;
|
|
return zir_f_76512f487eef232a_ReadLinkRaw(&(name[0]), &(byte), 1) > 0;
|
|
}
|
|
|
|
bool
|
|
PathExists(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
int32_t fd = file_linux_OpenPath(&(name[0]), 2097152, 0);
|
|
if (fd < 0) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_CloseRaw(fd) == 0;
|
|
}
|
|
|
|
bool
|
|
file_linux_DirectoryExists(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
int32_t fd = file_linux_OpenPath(&(name[0]), 2162688, 0);
|
|
if (fd < 0) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_CloseRaw(fd) == 0;
|
|
}
|
|
|
|
bool
|
|
RenamePath(String source, String destination)
|
|
{
|
|
uint8_t old_name[4096] = {0};
|
|
uint8_t new_name[4096] = {0};
|
|
Slice value_0 = {old_name, 4096};
|
|
bool value_1 = CopyCString(source, value_0);
|
|
bool value_2 = !value_1;
|
|
if (!value_2) {
|
|
Slice value_3 = {new_name, 4096};
|
|
bool value_4 = CopyCString(destination, value_3);
|
|
value_2 = !value_4;
|
|
}
|
|
if (value_2) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_RenameAtRaw(-100, &(old_name[0]), -100, &(new_name[0])) == 0;
|
|
}
|
|
|
|
bool
|
|
RenameNoReplace(String source, String destination)
|
|
{
|
|
uint8_t old_name[4096] = {0};
|
|
uint8_t new_name[4096] = {0};
|
|
Slice value_0 = {old_name, 4096};
|
|
bool value_1 = CopyCString(source, value_0);
|
|
bool value_2 = !value_1;
|
|
if (!value_2) {
|
|
Slice value_3 = {new_name, 4096};
|
|
bool value_4 = CopyCString(destination, value_3);
|
|
value_2 = !value_4;
|
|
}
|
|
if (value_2) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_RenameAt2Raw(-100, &(old_name[0]), -100, &(new_name[0]), 1) == 0;
|
|
}
|
|
|
|
bool
|
|
LinkFile(String source, String destination)
|
|
{
|
|
uint8_t old_name[4096] = {0};
|
|
uint8_t new_name[4096] = {0};
|
|
Slice value_0 = {old_name, 4096};
|
|
bool value_1 = CopyCString(source, value_0);
|
|
bool value_2 = !value_1;
|
|
if (!value_2) {
|
|
Slice value_3 = {new_name, 4096};
|
|
bool value_4 = CopyCString(destination, value_3);
|
|
value_2 = !value_4;
|
|
}
|
|
if (value_2) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_LinkRaw(&(old_name[0]), &(new_name[0])) == 0;
|
|
}
|
|
|
|
bool
|
|
CreateDirectory(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
if (zir_f_76512f487eef232a_MakeDirectoryRaw(&(name[0]), 493) == 0) {
|
|
return true;
|
|
}
|
|
return file_linux_DirectoryExists(path);
|
|
}
|
|
|
|
bool
|
|
CreatePrivateDirectory(String path)
|
|
{
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return false;
|
|
}
|
|
if (zir_f_76512f487eef232a_MakeDirectoryRaw(&(name[0]), 448) == 0) {
|
|
return true;
|
|
}
|
|
return file_linux_DirectoryExists(path);
|
|
}
|
|
|
|
int64_t
|
|
FileSize(FileHandle file)
|
|
{
|
|
if (!file.valid) {
|
|
return -1LL;
|
|
}
|
|
return zir_f_76512f487eef232a_SeekRaw(file.fd, 0LL, 2);
|
|
}
|
|
|
|
int64_t
|
|
ReadAt(FileHandle file, Slice output, int64_t offset)
|
|
{
|
|
if (!file.valid || offset < 0LL) {
|
|
return -1LL;
|
|
}
|
|
if ((int64_t)(output).length == 0LL) {
|
|
return 0LL;
|
|
}
|
|
ptrdiff_t value_0 = zir_f_76512f487eef232a_ReadAtRaw(file.fd, &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)0)]), (size_t)((int64_t)(output).length), offset);
|
|
return (int64_t)(value_0);
|
|
}
|
|
|
|
int64_t
|
|
WriteAt(FileHandle file, Slice input, int64_t offset)
|
|
{
|
|
if (!file.valid || offset < 0LL) {
|
|
return -1LL;
|
|
}
|
|
if ((int64_t)(input).length == 0LL) {
|
|
return 0LL;
|
|
}
|
|
ptrdiff_t value_0 = zir_f_76512f487eef232a_WriteAtRaw(file.fd, &(((uint8_t *)input.data)[SliceIndex(input, (int64_t)0)]), (size_t)((int64_t)(input).length), offset);
|
|
return (int64_t)(value_0);
|
|
}
|
|
|
|
int64_t
|
|
WriteTextAt(FileHandle file, String input, int64_t offset)
|
|
{
|
|
if (!file.valid || offset < 0LL) {
|
|
return -1LL;
|
|
}
|
|
int64_t length = (int64_t)(input).length;
|
|
if (length > (int64_t)(UINT64_C(9223372036854775807) - (uint64_t)offset)) {
|
|
return -1LL;
|
|
}
|
|
int64_t written = 0LL;
|
|
while (written < length) {
|
|
uint8_t buffer[4096] = {0};
|
|
int64_t count = (int64_t)((uint64_t)length - (uint64_t)written);
|
|
if (count > 4096LL) {
|
|
count = 4096LL;
|
|
}
|
|
int64_t index = 0LL;
|
|
while (index < count) {
|
|
uint8_t* value_0 = &(ZIRAN_INDEX(buffer, sizeof(buffer) / sizeof(buffer[0]), index));
|
|
(*value_0) = (uint8_t)ZIRAN_INDEX(input.data, input.length, ((int64_t)((uint64_t)written + (uint64_t)index)));
|
|
index = (int64_t)((uint64_t)index + UINT64_C(1));
|
|
}
|
|
Slice value_1 = {buffer, 4096};
|
|
int64_t result = WriteAt(file, SliceRange(value_1, (int64_t)0LL, (int64_t)count, sizeof(uint8_t)), (int64_t)((uint64_t)offset + (uint64_t)written));
|
|
if (result <= 0LL) {
|
|
return -1LL;
|
|
}
|
|
written = (int64_t)((uint64_t)written + (uint64_t)result);
|
|
}
|
|
return written;
|
|
}
|
|
|
|
bool
|
|
CloseFile(FileHandle file)
|
|
{
|
|
if (!file.valid) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_CloseRaw(file.fd) == 0;
|
|
}
|
|
|
|
bool
|
|
SyncFile(FileHandle file)
|
|
{
|
|
if (!file.valid) {
|
|
return false;
|
|
}
|
|
return zir_f_76512f487eef232a_SyncRaw(file.fd) == 0;
|
|
}
|
|
|
|
int64_t
|
|
Read(FileHandle file, Slice output)
|
|
{
|
|
if (!file.valid || (int64_t)(output).length > 2147483647LL) {
|
|
return -1LL;
|
|
}
|
|
if ((int64_t)(output).length == 0LL) {
|
|
return 0LL;
|
|
}
|
|
ptrdiff_t value_0 = zir_f_76512f487eef232a_ReadRaw(file.fd, &(((uint8_t *)output.data)[SliceIndex(output, (int64_t)0)]), (size_t)((int64_t)(output).length));
|
|
return (int64_t)(value_0);
|
|
}
|
|
|
|
int64_t
|
|
Write(FileHandle file, Slice input)
|
|
{
|
|
if (!file.valid || (int64_t)(input).length > 2147483647LL) {
|
|
return -1LL;
|
|
}
|
|
if ((int64_t)(input).length == 0LL) {
|
|
return 0LL;
|
|
}
|
|
ptrdiff_t value_0 = zir_f_76512f487eef232a_WriteRaw(file.fd, &(((uint8_t *)input.data)[SliceIndex(input, (int64_t)0)]), (size_t)((int64_t)(input).length));
|
|
return (int64_t)(value_0);
|
|
}
|
|
|
|
DirectoryCursor
|
|
OpenDirectory(String path)
|
|
{
|
|
DirectoryCursor result = {0};
|
|
uint8_t name[4096] = {0};
|
|
Slice value_0 = {name, 4096};
|
|
bool value_1 = CopyCString(path, value_0);
|
|
if (!value_1) {
|
|
return result;
|
|
}
|
|
void** value_2 = &(result.storage);
|
|
(*value_2) = zir_f_76512f487eef232a_OpenDirectoryRaw(&(name[0]));
|
|
bool* value_3 = &(result.valid);
|
|
(*value_3) = result.storage != ((void *)0);
|
|
return result;
|
|
}
|
|
|
|
DirectoryEntry
|
|
NextDirectoryEntry(DirectoryCursor* cursor)
|
|
{
|
|
DirectoryEntry result = {0};
|
|
if (cursor == ((void *)0) || !cursor->valid || cursor->failed) {
|
|
return result;
|
|
}
|
|
if (cursor->storage == ((void *)0)) {
|
|
bool* value_0 = &(cursor->failed);
|
|
(*value_0) = true;
|
|
return result;
|
|
}
|
|
int32_t* value_1 = zir_f_76512f487eef232a_DirectoryErrno();
|
|
int32_t* value_2 = &((*(value_1)));
|
|
(*value_2) = 0;
|
|
DirectoryMetadata* entry = zir_f_76512f487eef232a_ReadDirectoryRaw(cursor->storage);
|
|
if (entry == ((void *)0)) {
|
|
bool* value_3 = &(cursor->failed);
|
|
int32_t* value_4 = zir_f_76512f487eef232a_DirectoryErrno();
|
|
(*value_3) = *(value_4) != 0;
|
|
return result;
|
|
}
|
|
int32_t index = 0;
|
|
while (ZIRAN_INDEX(entry->name, 256, index) != 0) {
|
|
if (index >= 255) {
|
|
bool* value_5 = &(cursor->failed);
|
|
(*value_5) = true;
|
|
return result;
|
|
}
|
|
uint8_t* value_6 = &(ZIRAN_INDEX(result.name, sizeof(result.name) / sizeof(result.name[0]), index));
|
|
(*value_6) = ZIRAN_INDEX(entry->name, 256, index);
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
int32_t* value_7 = &(result.name_count);
|
|
(*value_7) = index;
|
|
bool* value_8 = &(result.valid);
|
|
(*value_8) = true;
|
|
DirectoryKind* value_9 = &(result.kind);
|
|
(*value_9) = DirectoryKind_Other;
|
|
if (entry->kind == 0) {
|
|
DirectoryKind* value_10 = &(result.kind);
|
|
(*value_10) = DirectoryKind_Unknown;
|
|
}
|
|
if (entry->kind == 4) {
|
|
DirectoryKind* value_11 = &(result.kind);
|
|
(*value_11) = DirectoryKind_Directory;
|
|
}
|
|
if (entry->kind == 8) {
|
|
DirectoryKind* value_12 = &(result.kind);
|
|
(*value_12) = DirectoryKind_Regular;
|
|
}
|
|
if (entry->kind == 10) {
|
|
DirectoryKind* value_13 = &(result.kind);
|
|
(*value_13) = DirectoryKind_Link;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool
|
|
CloseDirectory(DirectoryCursor* cursor)
|
|
{
|
|
if (cursor == ((void *)0) || !cursor->valid) {
|
|
return false;
|
|
}
|
|
int32_t status = zir_f_76512f487eef232a_CloseDirectoryRaw(cursor->storage);
|
|
void** value_0 = &(cursor->storage);
|
|
(*value_0) = (void *)0;
|
|
bool* value_1 = &(cursor->valid);
|
|
(*value_1) = false;
|
|
return status == 0;
|
|
}
|