example_apps_data.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <furi.h>
  2. #include <storage/storage.h>
  3. // Define log tag
  4. #define TAG "example_apps_data"
  5. // Application entry point
  6. int32_t example_apps_data_main(void* p) {
  7. // Mark argument as unused
  8. UNUSED(p);
  9. // Open storage
  10. Storage* storage = furi_record_open(RECORD_STORAGE);
  11. // Allocate file
  12. File* file = storage_file_alloc(storage);
  13. // Get the path to the current application data folder
  14. // That is: /ext/apps_data/<app_name>
  15. // And it will create folders in the path if they don't exist
  16. // In this example it will create /ext/apps_data/example_apps_data
  17. // And file will be /ext/apps_data/example_apps_data/test.txt
  18. // Open file, write data and close it
  19. if(!storage_file_open(file, APP_DATA_PATH("test.txt"), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
  20. FURI_LOG_E(TAG, "Failed to open file");
  21. }
  22. if(!storage_file_write(file, "Hello World!", strlen("Hello World!"))) {
  23. FURI_LOG_E(TAG, "Failed to write to file");
  24. }
  25. storage_file_close(file);
  26. // Deallocate file
  27. storage_file_free(file);
  28. // Close storage
  29. furi_record_close(RECORD_STORAGE);
  30. return 0;
  31. }