Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorial:file_operations [2020/11/20 01:16] iridescence [Zig] |
tutorial:file_operations [2021/12/23 09:45] (current) daveon_newearthlife [File Operations] |
||
---|---|---|---|
Line 2: | Line 2: | ||
In most software applications that require large sets of data or interaction which cannot be expressed before compile time, we use files to store large sets of data and other information that we may require for our programs. These files and folders can be accessed by our program in order to carry out the program' | In most software applications that require large sets of data or interaction which cannot be expressed before compile time, we use files to store large sets of data and other information that we may require for our programs. These files and folders can be accessed by our program in order to carry out the program' | ||
+ | |||
+ | |||
+ | |||
===== General Theory ===== | ===== General Theory ===== | ||
Line 53: | Line 56: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | In the C example we use the C FILE* in order to open the files via fopen and uses fprintf and fread in order to work with the file handle. In C++ we have to use an ifstream and ofstream to read and write respectively. The C example also will work in C++ - and you technically only need one FILE* in C. A pure fstream does not work in this instance on the PSP. In C++ we also use the getline method to read until a newline. | ||
===== Rust ===== | ===== Rust ===== | ||
Line 58: | Line 63: | ||
**main.rs** | **main.rs** | ||
<code Rust> | <code Rust> | ||
+ | #![no_std] | ||
+ | #![no_main] | ||
+ | psp:: | ||
+ | |||
+ | use psp:: | ||
+ | use core:: | ||
+ | |||
+ | pub fn psp_main() { | ||
+ | psp:: | ||
+ | | ||
+ | unsafe { | ||
+ | let fd = psp:: | ||
+ | psp:: | ||
+ | psp:: | ||
+ | |||
+ | let fd2 = psp:: | ||
+ | let array: [u8; 19] = [0; 19]; | ||
+ | |||
+ | psp:: | ||
+ | psp:: | ||
+ | |||
+ | if let Ok(s) = core:: | ||
+ | psp:: | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
</ | </ | ||
+ | |||
+ | In Rust, we use the IoFileMgr module in order to work on our application. This application requires that the hardcoded path is valid. We then write to a file opened in create mode and then close it. We then reopen it in read mode and then read to our array. Finally, we derive a string from the raw utf8 and print it out to the screen. | ||
===== Zig ===== | ===== Zig ===== | ||
Line 95: | Line 129: | ||
</ | </ | ||
+ | |||
+ | In Zig, we set up the Custom OS for STD via pub const os = @import(" |