MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SaveFile

Function SaveFile

Applications/TextEdit/main.cpp:57–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55}
56
57void SaveFile(const char* path){
58 struct stat sResult;
59 int ret = stat(path, &sResult);
60 if(ret && ret != ENOENT){
61 Lemon::GUI::DisplayMessageBox("Text Editor", strerror(ret), Lemon::GUI::MsgButtonsOK);
62 return;
63 }
64
65 if(S_ISDIR(sResult.st_mode)){
66 Lemon::GUI::DisplayMessageBox("Text Editor", "File is a directory!", Lemon::GUI::MsgButtonsOK);
67 return;
68 }
69
70 FILE* textFile = fopen(path, "w");
71
72 if(!textFile){
73 Lemon::GUI::DisplayMessageBox("Text Editor", "Failed to open file for writing!", Lemon::GUI::MsgButtonsOK);
74 return;
75 }
76
77 fseek(textFile, 0, SEEK_SET);
78
79 for(std::string& str : textBox->contents){
80 fwrite(str.c_str(), 1, str.length(), textFile);
81 fwrite("\n", 1, 1, textFile); // Line ending
82 }
83
84 fclose(textFile);
85
86 openPath = path;
87}
88
89void OpenFile(){
90

Callers 2

SaveFileAsFunction · 0.85
SaveOpenFileFunction · 0.85

Calls 3

DisplayMessageBoxFunction · 0.85
lengthMethod · 0.80
statClass · 0.70

Tested by

no test coverage detected