int main(){ /* infile - pointer to infile outfile - pointer to outfile indata - input data nodes - input path */ FILE *infile, *outfile; indata Bdata; path_node *nodes; infile = NULL; outfile = NULL; nodes=NULL; infile = fopen ("input.txt","r"); outfile = fopen ("output.txt","w"); loader(&Bdata, infile); int size = guider(&nodes, &Bdata); path_to_file(nodes, size, outfile); free(Bdata.P); free(Bdata.Q); free(nodes); fclose(infile); fclose(outfile); }
int sys_open(char* path) { u32 fd; struct file* fp; struct open_file* of; if (!(fp = path_to_file(path))) { // printk("DEBUG: sys_open(): can't open %s\n", path); return -1; } // printk("DEBUG: sys_open(): process[%d] opening file %s\n", current->pid, fp->name); fp->opened++; if (!fp->inode) fp->inode = ext2_read_inode(fp->disk, fp->inum); /* Lecture du fichier */ fp->mmap = ext2_read_file(fp->disk, fp->inode); /* * Recherche d'un descripteur libre. */ fd = 0; if (current->fd == 0) { current->fd = (struct open_file *) malloc(sizeof(struct open_file)); current->fd->file = fp; current->fd->ptr = 0; current->fd->next = 0; } else { of = current->fd; while (of->file && of->next) { of = of->next; fd++; } if (of->file == 0) /* Reuse old descriptor */ { of->file = fp; of->ptr = 0; } else /* Use new one */ { of->next = (struct open_file *) malloc(sizeof(struct open_file)); of->next->file = fp; of->next->ptr = 0; of->next->next = 0; fd++; } } return fd; }
Image::SaveResult Image::save(const QString &path, bool force, bool basic, bool addMd5, bool startCommands, int count, bool postSave) { SaveResult res = SaveResult::Saved; QFile f(path); if (!f.exists() || force) { QPair<QString, QString> md5action = m_profile->md5Action(md5()); QString whatToDo = md5action.first; QString md5Duplicate = md5action.second; // Only create the destination directory if we're going to put a file there if (md5Duplicate.isEmpty() || force || whatToDo != "ignore") { QString p = path.section(QDir::separator(), 0, -2); QDir path_to_file(p), dir; if (!path_to_file.exists() && !dir.mkpath(p)) { log(QStringLiteral("Impossible to create the destination folder: %1.").arg(p), Logger::Error); return SaveResult::Error; } } if (md5Duplicate.isEmpty() || whatToDo == "save" || force) { if (!m_savePath.isEmpty() && QFile::exists(m_savePath)) { log(QStringLiteral("Saving image in <a href=\"file:///%1\">%1</a> (from <a href=\"file:///%2\">%2</a>)").arg(path, m_savePath)); QFile(m_savePath).copy(path); } else { if (m_data.isEmpty()) { return SaveResult::NotLoaded; } log(QStringLiteral("Saving image in <a href=\"file:///%1\">%1</a>").arg(path)); if (f.open(QFile::WriteOnly)) { if (f.write(m_data) < 0) { f.close(); f.remove(); log(QStringLiteral("File saving error: %1)").arg(f.errorString()), Logger::Error); return SaveResult::Error; } f.close(); } else { log(QStringLiteral("Unable to open file")); return SaveResult::Error; } } } else if (whatToDo == "copy") { log(QStringLiteral("Copy from <a href=\"file:///%1\">%1</a> to <a href=\"file:///%2\">%2</a>").arg(md5Duplicate, path)); QFile(md5Duplicate).copy(path); res = SaveResult::Copied; } else if (whatToDo == "move") { log(QStringLiteral("Moving from <a href=\"file:///%1\">%1</a> to <a href=\"file:///%2\">%2</a>").arg(md5Duplicate, path)); QFile::rename(md5Duplicate, path); m_profile->setMd5(md5(), path); res = SaveResult::Moved; } else { log(QStringLiteral("MD5 \"%1\" of the image <a href=\"%2\">%2</a> already found in file <a href=\"file:///%3\">%3</a>").arg(md5(), url(), md5Duplicate)); return SaveResult::Ignored; } if (postSave) { postSaving(path, addMd5 && res == SaveResult::Saved, startCommands, count, basic); } } else { res = SaveResult::AlreadyExists; } return res; }