![]() | Fun 0.41.5 The programming language that makes You have fun |
Implements the OP_READ_FILE opcode for reading file contents in the VM. More...

Go to the source code of this file.
Functions | |
| if (path.type !=VAL_STRING) | |
| if (!f) | |
| if (fseek(f, 0, SEEK_END) !=0) | |
| if (sz< 0) | |
| rewind (f) | |
| fclose (f) | |
| free (buf) | |
| free_value (path) | |
| push_value (vm, out) | |
Variables | |
| case | OP_READ_FILE |
| const char * | p = path.s ? path.s : "" |
| FILE * | f = fopen(p, "rb") |
| long | sz = ftell(f) |
| char * | buf = (char *)malloc((size_t)sz + 1) |
| size_t | n = buf ? fread(buf, 1, (size_t)sz, f) : 0 |
| Value | out = make_string(buf) |
| break | |
Implements the OP_READ_FILE opcode for reading file contents in the VM.
This file handles the OP_READ_FILE instruction, which reads the contents of a file and pushes the result as a string onto the stack.
Behavior:
Error Handling:
Example: // Bytecode: OP_READ_FILE // Stack before: ["file.txt"] // Stack after: ["file contents"]
Definition in file read_file.c.
| fclose | ( | f | ) |

| free | ( | buf | ) |
| free_value | ( | path | ) |

| if | ( | ! | f | ) |
| if | ( | fseek(f, 0, SEEK_END) ! | = 0 | ) |
| if | ( | path.type ! | = VAL_STRING | ) |
Definition at line 33 of file read_file.c.
| if | ( | ) |
| push_value | ( | vm | , |
| out | ) |

| rewind | ( | f | ) |
| break |
Definition at line 71 of file read_file.c.
Definition at line 58 of file read_file.c.
| FILE* f = fopen(p, "rb") |
Definition at line 38 of file read_file.c.
| case OP_READ_FILE |
Definition at line 31 of file read_file.c.
| Value out = make_string(buf) |
Definition at line 67 of file read_file.c.
Definition at line 37 of file read_file.c.
| long sz = ftell(f) |
Definition at line 50 of file read_file.c.