/* Err... well, the pretty obvious sfscreate entry point * * return : 1 on argument missing - 0 on success * variables : A diskimage */ int main(int argc, char ** argv) { superblock spb; bitmap bpm; // bitmap = 1 block file_entries fes; // file entries = 16 block file_entry fie; // temporary file entry file_content fic; // file content = 1000 block // You shall not pass alone ! if (argc == 2 && (strcmp(argv[1], "-h") == 0 || (strcmp(argv[1], "--help") == 0))) { printf(HELP); printf(USAGE); return 1; } else if (argc != 2){ printf(USAGE); return 1; } /* Checking filename */ char * filename = checkFileName(argv[1]); // Initializing superblock createSuperBlock(&spb); // Initializing bitmap createBMP(&bpm); // Initializing file entries createFileEntries(&fes, &fie); // Initializing file content createFileContent(&fic); // Creating diskimage and writing down to it previously created elements printf(CREATEDISKIMG); FILE *fh = fopen (filename, "wb"); // w is write, b is ISO C compliance... if (fh != NULL) { fwrite (&spb, sizeof (superblock), 1, fh); fwrite (&bpm, sizeof (int8_t), BLOCK, fh); fwrite (&fes, sizeof (int8_t), 16*BLOCK, fh); fwrite (&fic, sizeof (int8_t), Max_block_file*BLOCK, fh); fclose (fh); } free(filename); return 0; }
bool CMainWindow::saveFile(QString fileName) { QFile file(fileName); if(file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << createFileContent(); file.close(); return true; } QMessageBox::critical(this, tr("Error"), tr("Unable to save file")); return false; }