File
Description
Cross-platform file handle. Linux uses an fd through direct syscalls, macOS uses an fd through libSystem, Windows uses a HANDLE. The API surface (FileOpen / Close / Read / Write / Seek / Tell / Flush / Eof) is identical across platforms.
Value type – caller stack-allocates and passes by pointer. A failed open leaves fd (or handle) negative / INVALID; check with FileIsOpen after open.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Std.h:44:
#if FEATURE_FILE
# include <Misra/Std/File.h>
#endif- In
ArgParse.h:44:
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/Container/Vec.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Types.h>- In
ArgParse.h:142:
Zstr about;
ArgSpecs specs;
File *out;
} ArgParse;- In
File.h:39:
bool at_eof; // last read returned 0 bytes
bool owns; // true when FileClose should release the handle
} File;
///
- In
File.h:78:
/// TAGS: File, Open, API
///
File file_open(Zstr path, Zstr mode);
#define FileOpen(path, mode) \
_Generic( \- In
File.h:104:
/// TAGS: File, FromFd, Wrap, FileDescriptor
///
File FileFromFd(i32 fd);
///
- In
File.h:117:
/// TAGS: File, Stdio, API
///
File FileStdin(void);
File FileStdout(void);
File FileStderr(void);- In
File.h:118:
///
File FileStdin(void);
File FileStdout(void);
File FileStderr(void);- In
File.h:119:
File FileStdin(void);
File FileStdout(void);
File FileStderr(void);
///
- In
File.h:131:
/// TAGS: File, Close, API
///
bool FileClose(File *f);
///
- In
File.h:141:
/// TAGS: File, Query, State, Open
///
bool FileIsOpen(const File *f);
///
- In
File.h:174:
/// TAGS: File, Read
///
i64 file_read(File *f, void *buf, u64 n);
i64 file_read_to_str(File *f, Str *out);
i64 file_read_to_buf(File *f, Buf *out);- In
File.h:175:
///
i64 file_read(File *f, void *buf, u64 n);
i64 file_read_to_str(File *f, Str *out);
i64 file_read_to_buf(File *f, Buf *out);
#define FileRead(...) OVERLOAD(FileRead, __VA_ARGS__)- In
File.h:176:
i64 file_read(File *f, void *buf, u64 n);
i64 file_read_to_str(File *f, Str *out);
i64 file_read_to_buf(File *f, Buf *out);
#define FileRead(...) OVERLOAD(FileRead, __VA_ARGS__)
#define FileRead_2(f, out) \- In
File.h:234:
/// TAGS: File, Write, API
///
i64 FileWrite(File *f, const void *buf, u64 n);
///
- In
File.h:285:
/// TAGS: File, Seek, Position
///
i64 FileSeek(File *f, i64 offset, FileWhence whence);
///
- In
File.h:295:
/// TAGS: File, Position, Tell
///
i64 FileTell(File *f);
///
- In
File.h:309:
/// TAGS: File, Flush, API
///
bool FileFlush(File *f);
///
- In
File.h:319:
/// TAGS: File, EOF, Query
///
bool FileIsEof(const File *f);
///
- In
File.h:330:
/// TAGS: File, FileDescriptor, API
///
i32 FileFd(const File *f);
///
- In
File.h:356:
/// TAGS: File, Temp
///
File file_open_temp(Str *out_path, Allocator *alloc);
#define FileOpenTemp(...) OVERLOAD(FileOpenTemp, __VA_ARGS__)
#define FileOpenTemp_1(out_path) file_open_temp((out_path), MisraScope)- In
Io.h:19:
#include <Misra/Std/DateTime.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/File.h>
#include <Misra/Types.h>- In
Io.h:688:
#define WriteFmt(...) \
do { \
File UNPL(out) = FileStdout(); \
FWriteFmt(&UNPL(out), __VA_ARGS__); \
} while (0)- In
Io.h:709:
#define WriteFmtLn(...) \
do { \
File UNPL(out) = FileStdout(); \
FWriteFmtLn(&UNPL(out), __VA_ARGS__); \
} while (0)- In
Io.h:731:
#define ReadFmt(...) \
do { \
File UNPL(in) = FileStdin(); \
FReadFmt(&UNPL(in), __VA_ARGS__); \
} while (0)- In
ProcMaps.h:24:
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/Container/Vec.h>
#include <Misra/Std/File.h>
#include <Misra/Types.h>- In
ProcMaps.h:97:
///
bool proc_maps_load_from_bytes(ProcMaps *out, const u8 *bytes, u64 len, Allocator *alloc);
bool proc_maps_load_from_file(ProcMaps *out, File *f, Allocator *alloc);
#define ProcMapsLoadFrom(...) OVERLOAD(ProcMapsLoadFrom, __VA_ARGS__)
#define ProcMapsLoadFrom_2(out, src) \- In
ProcMaps.h:102:
_Generic( \
(src), \
File *: proc_maps_load_from_file((out), (File *)(src), MisraScope), \
Str *: proc_maps_load_from_bytes((out), (const u8 *)StrBegin((Str *)(src)), StrLen((Str *)(src)), MisraScope), \
Buf *: proc_maps_load_from_bytes((out), BufData((Buf *)(src)), BufLength((Buf *)(src)), MisraScope) \
- In
ProcMaps.h:109:
_Generic( \
(src), \
File *: proc_maps_load_from_file((out), (File *)(src), ALLOCATOR_OF(alloc)), \
Str *: proc_maps_load_from_bytes( \
(out), \
- In
Sys.c:96:
#ifdef EEXIST
case EEXIST :
return "File exists";
#endif
#ifdef EXDEV- In
Sys.c:132:
#ifdef EFBIG
case EFBIG :
return "File too large";
#endif
#ifdef ENOSPC- In
Sys.c:164:
#ifdef ENAMETOOLONG
case ENAMETOOLONG :
return "File name too long";
#endif
#ifdef ENOTEMPTY- In
Log.c:30:
#include <Misra/Std/Allocator/Heap.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
Log.c:57:
StrAppendFmt(&full, "[{}] [{}:{}] {}\n", (Zstr)NAMES[type], (Zstr)tag, line, (Zstr)msg);
File out = (type == LOG_MESSAGE_TYPE_INFO) ? FileFromFd(1) : FileFromFd(2);
(void)FileWrite(&out, StrBegin(&full), StrLen(&full));- In
File.c:11:
#include <Misra/Std/Container/Buf.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Prng.h>- In
File.c:76:
// ---------------------------------------------------------------------------
File file_open(Zstr path, Zstr mode) {
File f = {0};
#if PLATFORM_WINDOWS- In
File.c:77:
File file_open(Zstr path, Zstr mode) {
File f = {0};
#if PLATFORM_WINDOWS
f.handle = INVALID_HANDLE_VALUE;- In
File.c:166:
}
File FileFromFd(i32 fd) {
File f = {0};
#if PLATFORM_WINDOWS- In
File.c:167:
File FileFromFd(i32 fd) {
File f = {0};
#if PLATFORM_WINDOWS
(void)fd;- In
File.c:178:
}
File FileStdin(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_INPUT_HANDLE), .owns = false};- In
File.c:180:
File FileStdin(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_INPUT_HANDLE), .owns = false};
return f;
#else- In
File.c:187:
}
File FileStdout(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_OUTPUT_HANDLE), .owns = false};- In
File.c:189:
File FileStdout(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_OUTPUT_HANDLE), .owns = false};
return f;
#else- In
File.c:196:
}
File FileStderr(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_ERROR_HANDLE), .owns = false};- In
File.c:198:
File FileStderr(void) {
#if PLATFORM_WINDOWS
File f = {.handle = GetStdHandle(STD_ERROR_HANDLE), .owns = false};
return f;
#else- In
File.c:205:
}
bool FileClose(File *f) {
if (!f) {
return false;- In
File.c:233:
}
bool FileIsOpen(const File *f) {
if (!f) {
return false;- In
File.c:248:
// ---------------------------------------------------------------------------
i64 file_read(File *f, void *buf, u64 n) {
if (!FileIsOpen(f) || !buf) {
return -1;- In
File.c:285:
}
i64 FileWrite(File *f, const void *buf, u64 n) {
if (!FileIsOpen(f) || !buf) {
return -1;- In
File.c:313:
}
i64 FileSeek(File *f, i64 offset, FileWhence whence) {
if (!FileIsOpen(f)) {
return -1;- In
File.c:342:
}
i64 FileTell(File *f) {
return FileSeek(f, 0, FILE_SEEK_CUR);
}- In
File.c:346:
}
bool FileFlush(File *f) {
if (!FileIsOpen(f)) {
return false;- In
File.c:360:
}
bool FileIsEof(const File *f) {
return f && f->at_eof;
}- In
File.c:364:
}
i32 FileFd(const File *f) {
#if PLATFORM_WINDOWS
(void)f;- In
ArgParse.c:10:
#include <Misra/Std/ArgParse.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
ArgParse.c:315:
static void print_help(ArgParse *self) {
File err = self->out ? *self->out : FileStderr();
if (self->about) {- In
ArgParse.c:475:
int argc,
char **argv,
File *err
) {
bool is_long = (tok[0] == '-' && tok[1] == '-');- In
ArgParse.c:581:
// when -v is a Flag or a Count. -lFOO (stuck value) is intentionally
// not supported in v1.
static ArgRun handle_short_bundle(ArgParse *self, Zstr tok, File *err) {
// tok looks like "-XYZ..."; verify every char maps to a Flag/Count.
ArgRun result = ARG_RUN_OK;- In
ArgParse.c:646:
}
File err = self->out ? *self->out : FileStderr();
bool rest_positional = false;- In
Io.c:15:
#include <Misra/Std/Container/Buf.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
Io.c:519:
}
bool f_write_fmt(File *stream, Zstr fmtstr, TypeSpecificIO *argv, u64 argc, bool append_newline) {
Str out;
bool ok = true;- In
Io.c:1126:
}
void f_read_fmt(File *file, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
// DefaultAllocator: the slurp buffer below sizes itself from file length
// (potentially many MiB on seekable inputs), so no stack-bound applies.
- In
Dir.c:25:
return "Unknown";
case DIR_ENTRY_TYPE_REGULAR_FILE :
return "Regular File";
case DIR_ENTRY_TYPE_DIRECTORY :
return "Directory";
#include <Misra/Std.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h> #include <Misra/Std/Memory.h>
#include <Misra/Std/File.h>
// ---------------------------------------------------------------------------
- In
PdbCache.c:14:
#include <Misra/Std.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
Dns.c:16:
#include <Misra/Std/Allocator/Arena.h>
#include <Misra/Std/Allocator/Heap.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
Dns.c:101:
// with an empty Str.
static bool slurp_file(Zstr path, Str *out) {
File f = FileOpen(path, "rb");
if (!FileIsOpen(&f)) {
// Missing config file is fine -- resolver just won't know about it.
- In
MachoCache.c:15:
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Memory.h>- In
_Helpers.h:13:
#define MISRA_SYS_HELPERS_H
#include <Misra/Std/File.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/Zstr.h>- In
_Helpers.h:23:
/// callers (cache lookups, sidecar discovery).
static inline bool sys_path_exists(Zstr path) {
File f = FileOpen(path, "rb");
if (!FileIsOpen(&f)) {
return false;- In
Pe.c:19:
#include <Misra/Std.h>
#include <Misra/Std/Container/Buf.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
Pdb.c:11:
#include <Misra/Parsers/Pdb.h>
#include <Misra/Std.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Math.h>- In
Tzif.c:16:
#include <Misra/Std.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
ProcMaps.c:27:
#include <Misra/Std/Memory.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Utility/StrIter.h>- In
ProcMaps.c:207:
// NOT EOF: treating it as one drops every later entry, including [stack]).
// Does not close `f`.
static bool proc_maps_read_all(File *f, Str *raw) {
enum {
CHUNK = 4096- In
ProcMaps.c:235:
// `/proc/self/maps` reports stat-size 0 because it's generated by the
// kernel on read, so we loop-read into a growing buffer ourselves.
File f = FileOpen("/proc/self/maps", "rb");
if (!FileIsOpen(&f)) {
LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");- In
ProcMaps.c:256:
}
bool proc_maps_load_from_file(ProcMaps *out, File *f, Allocator *alloc) {
if (!out || !f || !alloc) {
LOG_FATAL("ProcMapsLoadFrom: NULL argument");- In
Http.c:12:
#if FEATURE_FILE
# include <Misra/Std/File.h>
#endif- In
MachO.c:12:
#include <Misra/Parsers/MachO.h>
#include <Misra/Std.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
Elf.c:17:
#include <Misra/Std.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
File.c:3:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
File.c:15:
// caller can read it back and remove it.
static bool write_test_file(Zstr text, Str *out_path, Allocator *alloc) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f)) {
return false;- In
File.c:42:
}
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);- In
File.c:76:
}
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);- In
File.c:115:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
FileClose(&f);- In
File.c:149:
// "q" is not a recognised mode.
File f = FileOpen(&path, "q");
ok = ok && !FileIsOpen(&f);
FileClose(&f);- In
File.c:154:
// An empty mode is also rejected.
File g = FileOpen(&path, "");
ok = ok && !FileIsOpen(&g);
FileClose(&g);- In
File.c:175:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:224:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);- In
File.c:259:
}
File w = FileOpen(&path, "w");
ok = ok && FileIsOpen(&w);
ok = ok && (FileWrite(&w, "new", 3) == 3);- In
File.c:264:
FileClose(&w);
File r = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&r);
Str body = StrInit(alloc_base);- In
File.c:294:
}
File a = FileOpen(&path, "a");
ok = ok && FileIsOpen(&a);
ok = ok && (FileWrite(&a, "tail", 4) == 4);- In
File.c:299:
FileClose(&a);
File r = FileOpen(&path, "rb");
Str body = StrInit(alloc_base);
i64 got = FileRead(&r, &body);- In
File.c:325:
// then write to it through the convenience API.
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:359:
// Mint a unique name then remove it so the path is guaranteed absent.
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:396:
}
File f = FileOpen(&path, "r");
ok = ok && FileIsOpen(&f);
// A read-only handle must reject writes.
- In
File.c:423:
}
File f = FileOpen(&path, "r+");
ok = ok && FileIsOpen(&f);
// "r+" must permit writes (does not truncate). Overwrite first 3 bytes.
- In
File.c:431:
// Confirm the write landed.
Str body = StrInit(alloc_base);
File r = FileOpen(&path, "rb");
i64 got = FileRead(&r, &body);
FileClose(&r);- In
File.c:459:
}
File f = FileOpen(&path, "r");
ok = ok && FileIsOpen(&f);
char buf[8] = {0};- In
File.c:492:
#else
// fd 1 (stdout) is a stable, known descriptor.
File f = FileFromFd(1);
bool ok = (FileFd(&f) == 1);
// A different fd surfaces distinctly too.
- In
File.c:495:
bool ok = (FileFd(&f) == 1);
// A different fd surfaces distinctly too.
File g = FileFromFd(0);
ok = ok && (FileFd(&g) == 0);
return ok;- In
File.c:511:
Str path;
File owner = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&owner)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:521:
// the fd is left open; if the mutant set owns=true, this close would
// really close the fd and the subsequent owner write would fail.
File borrowed = FileFromFd(FileFd(&owner));
FileClose(&borrowed);- In
File.c:553:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:579:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:609:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:644:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
char buf[4] = {0};- In
File.c:677:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
char buf[8] = {0};- In
File.c:707:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:749:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
// Move the cursor to offset 10; remaining size must be 16 - 10 = 6.
- In
File.c:783:
}
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
Str body = StrInit(alloc_base);- In
File.c:814:
// Build a 10000-byte payload (> FILE_READ_CHUNK=4096) on disk.
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:830:
FileClose(&f);
File r = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&r);
Buf dst = BufInit(alloc_base);- In
File.c:860:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:923:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:958:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:996:
Str path;
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);
// The resolved path must be non-empty (16 hex chars).
- In
File.c:1025:
Str p1;
File f1 = FileOpenTemp(&p1, alloc_base);
Str p2;
File f2 = FileOpenTemp(&p2, alloc_base);- In
File.c:1027:
File f1 = FileOpenTemp(&p1, alloc_base);
Str p2;
File f2 = FileOpenTemp(&p2, alloc_base);
bool ok = FileIsOpen(&f1) && FileIsOpen(&f2);- In
File.c:1069:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
File.c:1101:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (FileIsOpen(&seed)) {
FileClose(&seed);- In
File.c:1132:
// fd 0 (stdin) is a valid, open descriptor. `>= 0` must accept it;
// a `> 0` mutant would wrongly report it not-open.
File f = FileFromFd(0);
bool ok = (FileIsOpen(&f) == true);
// Sanity: a genuinely-negative fd is not open under either form, so
- In
File.c:1136:
// Sanity: a genuinely-negative fd is not open under either form, so
// the discriminating case really is fd == 0.
File g = FileFromFd(-1);
ok = ok && (FileIsOpen(&g) == false);
return ok;- In
File.c:1196:
// middle of the table. Record A's fd.
Str pa;
File a = FileOpenTemp(&pa, alloc_base);
Str pb;
File b = FileOpenTemp(&pb, alloc_base);- In
File.c:1198:
File a = FileOpenTemp(&pa, alloc_base);
Str pb;
File b = FileOpenTemp(&pb, alloc_base);
if (!FileIsOpen(&a) || !FileIsOpen(&b)) {
if (FileIsOpen(&a)) {- In
File.c:1224:
// occupied so we get a strictly higher number.
Str pc;
File c = FileOpenTemp(&pc, alloc_base);
ok = ok && FileIsOpen(&c);
i32 fd_c = FileFd(&c);- In
File.c:1242:
int main(void) {
WriteFmt("[INFO] Starting File tests\n\n");
TestFunction tests[] = {- In
File.c:1290:
deadend_tests,
sizeof(deadend_tests) / sizeof(deadend_tests[0]),
"File"
);
}- In
ArgParse.c:7:
#include <Misra/Std/ArgParse.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io.h>
#include <Misra/Std/Log.h>- In
ArgParse.c:617:
static void capture_help(ArgParse *p, Str *out) {
Str tmp_path = StrInit(p->alloc);
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))- In
ArgParse.c:888:
static bool capture_help_file(ArgParse *p, Str *out) {
Str tmp_path = StrInit(p->alloc);
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))- In
ArgParse.c:1775:
static ArgRun capture_run(ArgParse *p, int argc, char **argv, Str *out) {
Str tmp_path = StrInit(p->alloc);
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))- In
Write.c:14:
#include <Misra/Std/Allocator.h>
#include <Misra/Std/Container/Buf.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Io/Private.h>
#include <Misra/Std/Memory.h>- In
Write.c:971:
// File (positioned at 0) and stashing the path in `*out_path` so the
// caller can FileRemove + StrDeinit it afterwards.
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))- In
Write.c:972:
// caller can FileRemove + StrDeinit it afterwards.
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))
return f;- In
Write.c:980:
}
static void m4_cleanup(File *f, Str *path) {
FileClose(f);
FileRemove(path);- In
Write.c:1010:
static bool roundtrip_eq(Zstr path, Zstr expect) {
DefaultAllocator alloc = DefaultAllocatorInit();
File f = FileOpen(path, "r");
bool ok = false;
if (FileIsOpen(&f)) {- In
Write.c:3032:
static bool test_m28_fwrite_roundtrip_string(void) {
Zstr path = "io_mutants28_str.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;- In
Write.c:3049:
static bool test_m28_fwrite_roundtrip_int(void) {
Zstr path = "io_mutants28_int.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;- In
Write.c:3066:
static bool test_m28_fwriteln_roundtrip(void) {
Zstr path = "io_mutants28_ln.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;- In
Write.c:4191:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "42 zzzzzzz", 10);
bool ok = FileIsOpen(&f);- In
Write.c:4216:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "7", 1);
bool ok = FileIsOpen(&f);- In
Write.c:4241:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "53 and more text", 16);
bool ok = FileIsOpen(&f);- In
Write.c:4991:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {- In
Write.c:4996:
ok = ok && FWriteFmtLn(&f, "n={}", LVAL((i32)42));
FileClose(&f);
File r = FileOpen(StrBegin(&path), "r");
if (FileIsOpen(&r)) {
Str back = StrInit(&alloc);- In
Write.c:5020:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {- In
Write.c:5027:
ok = ok && FWriteFmt(&f, "X");
FileClose(&f);
File r = FileOpen(StrBegin(&path), "r");
if (FileIsOpen(&r)) {
Str back = StrInit(&alloc);- In
Read.c:11:
#include <Misra/Std/Io.h>
#include <Misra/Std/Io/Private.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Memory.h>- In
Read.c:39:
// File (positioned at 0) and stashing the path in `*out_path` so the
// caller can FileRemove + StrDeinit it afterwards.
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))- In
Read.c:40:
// caller can FileRemove + StrDeinit it afterwards.
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))
return f;- In
Read.c:48:
}
static void m4_cleanup(File *f, Str *path) {
FileClose(f);
FileRemove(path);- In
Read.c:1653:
content[51] = '1';
File f = m4_make_temp(&alloc, &path, content, 52);
bool ok = FileIsOpen(&f);- In
Read.c:1674:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "", 0);
bool ok = FileIsOpen(&f);- In
Read.c:2683:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {- In
Read.c:2705:
DefaultAllocator alloc = DefaultAllocatorInit();
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {- In
PdbCache.c:89:
// Use Misra's File API so this test runs under -nostdlib too
// (no libc fopen/fwrite/fclose).
File f = FileOpen(path, "w");
if (!FileIsOpen(&f))
return false;- In
SysDns.c:18:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Str/Init.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Std/Zstr.h>- In
SysDns.c:100:
static Str write_temp(Allocator *a, Zstr body) {
Str path = StrInit(a);
File f = file_open_temp(&path, a);
if (FileIsOpen(&f)) {
u64 n = ZstrLen(body);- In
MachoCache.c:18:
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Memory.h>
#include <Misra/Std/File.h>
#include <Misra/Sys.h>
#include <Misra/Sys/MachoCache.h>- In
MachoCache.c:44:
static bool write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;- In
MachoCache.c:306:
static bool mc_write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;- In
MachoCache.c:923:
static bool bl_write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;- In
Pe.c:16:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Memory.h>
#include <Misra/Sys/Dir.h>- In
Pe.c:1651:
Str path = StrInit(base);
File f = FileOpenTemp(&path, base);
if (!FileIsOpen(&f)) {
StrDeinit(&path);- In
Pe.c:1693:
Str path = StrInit(base);
File f = FileOpenTemp(&path, base);
if (!FileIsOpen(&f)) {
StrDeinit(&path);- In
Pdb.c:17:
#include <Misra/Std/Allocator/Debug.h>
#include <Misra/Std/Container/Buf.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Memory.h>- In
ProcMaps.c:5:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Parsers/ProcMaps.h>- In
ProcMaps.c:571:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);- In
ProcMaps.c:598:
}
File rf = FileOpen(&path, "rb");
if (!FileIsOpen(&rf)) {
FileRemove(&path);- In
ProcMaps.c:639:
// A directory: open(2) succeeds (FileIsOpen true) but read(2) returns -1.
File dir = FileOpen("/proc/self", "rb");
if (!FileIsOpen(&dir)) {
DebugAllocatorDeinit(&dbg);- In
Http.c:3:
#include <Misra.h>
#include <Misra/Parsers/Http.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Zstr.h>
#include <Misra/Std/Allocator/Debug.h>- In
Http.c:214:
Str path = StrInit(alloc_base);
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);- In
Http.c:244:
Str path = StrInit(alloc_base);
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);
FileClose(&f); // leave it empty
- In
Http.c:388:
// Create a temp file with content.
Str path = StrInit(adbg);
File f = FileOpenTemp(&path, adbg);
bool ok = FileIsOpen(&f);
Zstr payload = "file-payload-long-enough-to-heap-allocate-body";- In
MachO.c:12:
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/Container/Str.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Memory.h>
#include <Misra/Std/Zstr.h>- In
MachO.c:1407:
// Mint a unique temp path, then write a minimal valid Mach-O to it.
Str path;
File seed = FileOpenTemp(&path, base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
MachO.c:1449:
Str path;
File seed = FileOpenTemp(&path, base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);- In
Elf.c:4:
#include <Misra/Parsers/Elf.h>
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Memory.h>- In
Stripped.c:19:
#include <Misra/Parsers/Elf.h>
#include <Misra/Std/Allocator/Default.h>
#include <Misra/Std/File.h>
#include <Misra/Std/Log.h>
#include <Misra/Sys/SymbolResolver.h>
Last updated on