flash_fs.c 667 B

12345678910111213141516171819202122232425262728
  1. #include "flash_fs.h"
  2. #include "c_string.h"
  3. #include "spiffs.h"
  4. int fs_mode2flag(const char *mode){
  5. if(c_strlen(mode)==1){
  6. if(c_strcmp(mode,"w")==0)
  7. return FS_WRONLY|FS_CREAT|FS_TRUNC;
  8. else if(c_strcmp(mode, "r")==0)
  9. return FS_RDONLY;
  10. else if(c_strcmp(mode, "a")==0)
  11. return FS_WRONLY|FS_CREAT|FS_APPEND;
  12. else
  13. return FS_RDONLY;
  14. } else if (c_strlen(mode)==2){
  15. if(c_strcmp(mode,"r+")==0)
  16. return FS_RDWR;
  17. else if(c_strcmp(mode, "w+")==0)
  18. return FS_RDWR|FS_CREAT|FS_TRUNC;
  19. else if(c_strcmp(mode, "a+")==0)
  20. return FS_RDWR|FS_CREAT|FS_APPEND;
  21. else
  22. return FS_RDONLY;
  23. } else {
  24. return FS_RDONLY;
  25. }
  26. }