FileOpen
Description
Open a file. mode is libc-compatible: "r"/"rb", "w"/"wb", "a"/"ab", "r+"/"rb+"/"r+b", "w+", "a+". Binary is always implied; the "b" suffix is accepted for compatibility but has no effect on the implementation.
Success
Returns a File where FileIsValid(&out) is true.
Failure
Returns a File where FileIsValid(&out) is false.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
PdbCache.c:24:
static bool path_exists(const char *path) {
File f = FileOpen(path, "rb");
if (!FileIsValid(&f)) {
return false;- In
MachoCache.c:23:
static bool path_exists(const char *path) {
File f = FileOpen(path, "rb");
if (!FileIsValid(&f)) {
return false; // Check whether `path` exists and is non-empty.
static bool path_exists(const char *path) {
File f = FileOpen(path, "rb");
if (!FileIsValid(&f)) {
return false;- In
ProcMaps.c:171:
// buffer size and short-circuits to empty — we have to loop-read
// into a growing buffer ourselves.
File f = FileOpen("/proc/self/maps", "rb");
if (!FileIsValid(&f)) {
LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");- In
ProcMaps.c:173:
File f = FileOpen("/proc/self/maps", "rb");
if (!FileIsValid(&f)) {
LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");
ProcMapsDeinit(out);
return false;- In
File.c:38:
(void)mode;
(void)out_flags;
return false; // Windows uses a different mode encoding (see FileOpen).
#else
if (!mode || !*mode) {- In
File.c:74:
// ---------------------------------------------------------------------------
File FileOpen(const char *path, const char *mode) {
File f = {0};
#ifdef _WIN32- In
File.c:106:
HANDLE h = CreateFileA(path, access, FILE_SHARE_READ, NULL, disposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
LOG_ERROR("FileOpen: CreateFileA(\"{}\") failed (err {})", path, (u32)GetLastError());
return f;
}- In
File.c:119:
int flags;
if (!parse_open_mode(mode, &flags)) {
LOG_ERROR("FileOpen: invalid mode \"{}\"", mode);
return f;
}- In
File.c:135:
# endif
if (fd < 0) {
LOG_ERROR("FileOpen: open(\"{}\") failed (errno {})", path, (i32)-fd);
return f;
}- In
File.c:383:
}
File f = FileOpen(filename, "rb");
if (!FileIsValid(&f)) {
return false;- In
ElfInfo.c:342:
}
File elf = FileOpen(argv[1], "rb");
if (!FileIsValid(&elf)) {
LOG_ERROR("Failed to open file for reading.");
Last updated on