forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathfile_io.tc
More file actions
41 lines (34 loc) · 930 Bytes
/
Copy pathfile_io.tc
File metadata and controls
41 lines (34 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// File I/O demo — write and read back
// On ESP32: uses LittleFS, in browser: simulated virtual filesystem
int main() {
char data[64];
char buf[64];
// Prepare data to write
strcpy(data, "Hello from TinyC!\n");
// Write to file (r=read, w=write, a=append)
int f = fileOpen("/test.txt", w);
if (f >= 0) {
fileWrite(f, data, strlen(data));
fileClose(f);
printStr("Written OK\n");
}
// Read back
f = fileOpen("/test.txt", r);
if (f >= 0) {
int n = fileRead(f, buf, 63);
buf[n] = 0; // null-terminate
fileClose(f);
printStr("Read back: ");
printString(buf);
}
// Check file info
if (fileExists("/test.txt")) {
printStr("File size: ");
print(fileSize("/test.txt"));
printStr("\n");
}
// Clean up
fileDelete("/test.txt");
printStr("File deleted\n");
return 0;
}