/* Create an shm file and map it. */ void * shm_create(struct shm *shm, size_t size) { int saved_errno; char *path; if (size == 0) fatalx("zero size"); if (ppath( shm->name, sizeof shm->name, "%s.XXXXXXXXXX", __progname) != 0) return (NULL); if ((path = shm_path(shm)) == NULL) return (NULL); if ((shm->fd = mkstemp(path)) == -1) return (NULL); strlcpy(shm->name, xbasename(path), sizeof shm->name); if (shm_expand(shm, size) != 0) goto error; shm->data = mmap(NULL, size, SHM_PROT, SHM_FLAGS, shm->fd, 0); if (shm->data == MAP_FAILED) goto error; madvise(shm->data, size, MADV_SEQUENTIAL); shm->size = size; return (shm->data); error: saved_errno = errno; unlink(path); errno = saved_errno; return (NULL); }
/* Work out shm path. */ char * shm_path(struct shm *shm) { static char path[MAXPATHLEN]; if (ppath(path, sizeof path, "%s/%s", conf.tmp_dir, shm->name) != 0) return (NULL); return (path); }
FILE* PlumedMain::fopen(const char *path, const char *mode){ std::string mmode(mode); std::string ppath(path); std::string suffix(getSuffix()); std::string ppathsuf=ppath+suffix; FILE*fp=std::fopen(const_cast<char*>(ppathsuf.c_str()),const_cast<char*>(mmode.c_str())); if(!fp) fp=std::fopen(const_cast<char*>(ppath.c_str()),const_cast<char*>(mmode.c_str())); plumed_massert(fp,"file " + ppath + " cannot be found"); return fp; }
CIFStreeconnect(Session *s, char *cname, char *tree, Share *sp) { int len; char *resp, *path; char zeros[24]; Pkt *p; resp = Sess->auth->resp[0]; len = Sess->auth->len[0]; if((s->secmode & SECMODE_USER) != SECMODE_USER){ memset(zeros, 0, sizeof zeros); resp = zeros; len = sizeof zeros; } p = cifshdr(s, nil, SMB_COM_TREE_CONNECT_ANDX); p8(p, 0xFF); /* Secondary command */ p8(p, 0); /* Reserved */ pl16(p, 0); /* Offset to next Word Count */ pl16(p, 0); /* Flags */ if((s->secmode & SECMODE_PW_ENCRYPT) == 0){ pl16(p, len+1); /* password len, including null */ pbytes(p); pascii(p, resp); }else{ pl16(p, len); pbytes(p); pmem(p, resp, len); } path = smprint("//%s/%s", cname, tree); ppath(p, path); /* path */ free(path); pascii(p, "?????"); /* service type any (so we can do RAP calls) */ if(cifsrpc(p) == -1){ free(p); return -1; } g8(p); /* Secondary command */ g8(p); /* Reserved */ gl16(p); /* Offset to next command */ sp->options = g8(p); /* options supported */ sp->tid = p->tid; /* get received TID from packet header */ free(p); return 0; }
int CIFScreatedirectory(Session *s, Share *sp, char *name) { int rc; Pkt *p; p = cifshdr(s, sp, SMB_COM_CREATE_DIRECTORY); pbytes(p); p8(p, STR_ASCII); ppath(p, name); rc = cifsrpc(p); free(p); return rc; }
int CIFSdeletedirectory(Session *s, Share *sp, char *name) { int rc; Pkt *p; p = cifshdr(s, sp, SMB_COM_DELETE_DIRECTORY); pbytes(p); p8(p, STR_ASCII); /* buffer format */ ppath(p, name); rc = cifsrpc(p); free(p); return rc; }
int CIFSdeletefile(Session *s, Share *sp, char *name) { int rc; Pkt *p; p = cifshdr(s, sp, SMB_COM_DELETE); pl16(p, ATTR_HIDDEN|ATTR_SYSTEM); /* search attributes */ pbytes(p); p8(p, STR_ASCII); /* buffer format */ ppath(p, name); rc = cifsrpc(p); free(p); return rc; }
/* Remove lock file. */ void rmlock(u_int locks, const char *path) { char lock[MAXPATHLEN]; if (!(locks & LOCK_DOTLOCK)) return; if (ppath(lock, sizeof lock, "%s.lock", path) != 0) fatal("unlink failed"); if (unlink(lock) != 0) fatal("unlink failed"); cleanup_deregister(lock); }
/* Make lock file. */ int mklock(u_int locks, const char *path) { char lock[MAXPATHLEN]; int fd; if (!(locks & LOCK_DOTLOCK)) return (0); if (ppath(lock, sizeof lock, "%s.lock", path) != 0) return (-1); fd = xcreate(lock, O_WRONLY, -1, -1, S_IRUSR|S_IWUSR); if (fd == -1) { if (errno == EEXIST) errno = EAGAIN; return (-1); } close(fd); cleanup_register(lock); return (0); }
Kb::Kb(QObject *parent, const QString& path) : QThread(parent), devpath(path), cmdpath(path + "/cmd"), features("N/A"), firmware("N/A"), pollrate("N/A"), _currentProfile(0), _currentMode(0), _model(KeyMap::NO_MODEL), _hwProfile(0), prevProfile(0), prevMode(0), cmd(cmdpath), notifyNumber(1), _needsSave(false) { memset(hwLoading, 0, sizeof(hwLoading)); // Get the features, model, serial number, FW version (if available), and poll rate (if available) from /dev nodes QFile ftpath(path + "/features"), mpath(path + "/model"), spath(path + "/serial"), fwpath(path + "/fwversion"), ppath(path + "/pollrate"); if(ftpath.open(QIODevice::ReadOnly)){ features = ftpath.read(1000); features = features.trimmed(); ftpath.close(); // Read model from features (first word: vendor, second word: product) QStringList list = features.split(" "); if(list.length() < 2) return; _model = KeyMap::getModel(list[1]); if(_model == KeyMap::NO_MODEL) return; } else // Bail if features aren't readable return; if(mpath.open(QIODevice::ReadOnly)){ usbModel = mpath.read(100); usbModel = usbModel.remove("Corsair").remove("Gaming").remove("Keyboard").remove("Mouse").remove("Bootloader").trimmed(); mpath.close(); } if(usbModel == "") usbModel = "Keyboard"; if(spath.open(QIODevice::ReadOnly)){ usbSerial = spath.read(100); usbSerial = usbSerial.trimmed().toUpper(); spath.close(); } if(usbSerial == "") usbSerial = "Unknown-" + usbModel; if(features.contains("fwversion") && fwpath.open(QIODevice::ReadOnly)){ firmware = fwpath.read(100); firmware = QString::number(firmware.trimmed().toInt() / 100., 'f', 2); fwpath.close(); } if(features.contains("pollrate") && ppath.open(QIODevice::ReadOnly)){ pollrate = ppath.read(100); pollrate = pollrate.trimmed(); ppath.close(); } hwModeCount = (_model == KeyMap::K95) ? 3 : 1; // Open cmd in non-blocking mode so that it doesn't lock up if nothing is reading // (e.g. if the daemon crashed and didn't clean up the node) int fd = open(cmdpath.toLatin1().constData(), O_WRONLY | O_NONBLOCK); if(!cmd.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) return; // Find an available notification node (if none is found, take notify1) for(int i = 1; i < 10; i++){ QString notify = QString(path + "/notify%1").arg(i); if(!QFile::exists(notify)){ notifyNumber = i; notifyPath = notify; break; } } cmd.write(QString("notifyon %1\n").arg(notifyNumber).toLatin1()); cmd.flush(); // Activate device, apply settings, and ask for hardware profile cmd.write(QString("fps %1\n").arg(_frameRate).toLatin1()); cmd.write(QString("dither %1\n").arg(static_cast<int>(_dither)).toLatin1()); #ifdef Q_OS_MACX // Write ANSI/ISO flag to daemon (OSX only) cmd.write("layout "); cmd.write(KeyMap::isISO(_layout) ? "iso" : "ansi"); #endif cmd.write(QString("\nactive\n@%1 get :hwprofileid").arg(notifyNumber).toLatin1()); hwLoading[0] = true; for(int i = 0; i < hwModeCount; i++){ cmd.write(QString(" mode %1 get :hwid").arg(i + 1).toLatin1()); hwLoading[i + 1] = true; } cmd.write("\n"); cmd.flush(); emit infoUpdated(); activeDevices.insert(this); // Start a separate thread to read from the notification node start(); }
bool VDFileIsRelativePath(const wchar_t *path) { VDParsedPath ppath(path); return ppath.IsRelative(); }
/* Save mbox changes. */ int fetch_mbox_save(struct account *a, struct fetch_mbox_mbox *fmbox) { struct fetch_mbox_data *data = a->data; struct fetch_mbox_mail *aux, *this; char path[MAXPATHLEN], saved[MAXPATHLEN], c; int fd; ssize_t n; struct iovec iov[2]; log_debug2("%s: %s: saving mbox: %u kept, %u total", a->name, fmbox->path, fmbox->reference, fmbox->total); fd = -1; /* * If the reference count is 0, no mails were kept, so the mbox can * just be truncated. */ if (fmbox->reference == 0) { if (fmbox->total != 0 && ftruncate(fmbox->fd, 0) != 0) goto error; goto free_all; } /* If all the mails were kept, do nothing. */ if (fmbox->reference == fmbox->total) goto free_all; /* * Otherwise, things get complicated. data->kept is a list of all the * mails (struct fetch_mbox_mail) which were kept for ALL mailboxes. * There is no guarantee it is ordered by offset. Rather than try to be * clever and save disk space, just create a new mbox and copy all the * kept mails into it. */ if (ppath(path, sizeof path, "%s.XXXXXXXXXX", fmbox->path) != 0) goto error; if (ppath(saved, sizeof saved, "%s.XXXXXXXXXX", fmbox->path) != 0) goto error; if ((fd = mkstemp(path)) == -1) goto error; aux = TAILQ_FIRST(&data->kept); while (aux != NULL) { this = aux; aux = TAILQ_NEXT(aux, entry); if (this->fmbox != fmbox) continue; log_debug2("%s: writing message from %zu, size %zu", a->name, this->off, this->size); c = '\n'; iov[0].iov_base = fmbox->base + this->off; iov[0].iov_len = this->size; iov[1].iov_base = &c; iov[1].iov_len = 1; if ((n = writev(fd, iov, 2)) < 0) goto error; if ((size_t) n != this->size + 1) { errno = EIO; goto error; } fetch_mbox_free(this); TAILQ_REMOVE(&data->kept, this, entry); } if (fsync(fd) != 0) goto error; close(fd); /* * Do the replacement dance: create a backup copy of the mbox, remove * the mbox, link in the temporary file, unlink the temporary file, * then unlink the backup mbox. We don't try to recover if anything * fails on the grounds that it could just make things worse, just * die and let the user sort it out. */ if (link(fmbox->path, saved) != 0) goto error; if (unlink(fmbox->path) != 0) goto error; if (link(path, fmbox->path) != 0) goto error; if (unlink(path) != 0) goto error; if (unlink(saved) != 0) goto error; free_all: aux = TAILQ_FIRST(&data->kept); while (aux != NULL) { this = aux; aux = TAILQ_NEXT(aux, entry); if (this->fmbox == fmbox) fetch_mbox_free(this); } if (fmbox->reference != 0) fatalx("dangling reference"); return (0); error: if (fd != -1) { close(fd); unlink(path); } log_warn("%s: %s", a->name, fmbox->path); return (-1); }
void modeltest::CreateGUIControls(void) { //char line[1000]; wxString title = "MrMTgui"; this->SetSize(8,8,700,450); this->SetTitle(wxString(title)); this->Center(); wxIcon icon; wxBitmap bitmap(wxT("mtgui.png"), wxBITMAP_TYPE_PNG); icon.CopyFromBitmap(bitmap); this->SetIcon(icon); wxPanel *mainPanel = new wxPanel(this, mpanel, wxDefaultPosition, wxDefaultSize); wxStaticText *MT = new wxStaticText(mainPanel, -1,"ModelTest", wxPoint(16,10),wxDefaultSize); wxStaticText *MrMT = new wxStaticText(mainPanel, -1,"MrModelTest", wxPoint(580,10),wxDefaultSize); //ModelTest "panel" - left side/////////////////////////////////////////////////////////////////// runPAUP = new wxButton(mainPanel, paupBt, _("Run PAUP") ,wxPoint(16, 30) ,wxSize(95,30)); selectFile = new wxButton(mainPanel, fileBt, _("Select file ...") , wxPoint(16,70),wxSize(95,30)); parameters = new wxButton(mainPanel, paramBt, _("Parameters"), wxPoint(16,110), wxSize(95,30)); runModel = new wxButton(mainPanel, modelBt, _("Modeltest !!") , wxPoint(16,150),wxSize(95,30)); runModel->SetToolTip(wxT("Run modeltest and get your results")); checkBIC = new wxCheckBox(mainPanel, -1, _T("Use BIC (-b)"), wxPoint(16, 190), wxDefaultSize); inNexus = new wxButton(mainPanel, nexus, _("Edit NEXUS") ,wxPoint(16, 230) ,wxSize(95,30)); inNexus->Enable(false); ///////////////////////////////////////////////////////////////////////////////////////////////// //MrModelTest "panel"- right side//////////////////////////////////////////////////////////////// runBayes = new wxButton(mainPanel, bayesBt, _("Run Paup") ,wxPoint(580, 30) ,wxSize(95,30)); selectFileMr = new wxButton(mainPanel, fileMrBt, _("Select file ...") , wxPoint(580,70),wxSize(95,30)); //parameters = new wxButton(mainPanel, paramBt, _("Parameters"), wxPoint(16,100), wxSize(95,30)); runMr = new wxButton(mainPanel, mrBt, _("MrModeltest !!!") , wxPoint(580,150),wxSize(95,30)); runMr->SetToolTip(wxT("Run MrModeltest and get your results")); inMrNexus = new wxButton(mainPanel, mrNexus, _("Edit NEXUS") ,wxPoint(580, 190) ,wxSize(95,30)); inMrNexus->Enable(false); ///////////////////////////////////////////////////////////////////////////////////////////////// modelpath = new wxButton(mainPanel, pathBt, _("MT path") ,wxPoint(120, 350) ,wxSize(95,30) ); modelpath->Enable(false); pauppath = new wxButton(mainPanel, pathPaup, _("PAUP path") ,wxPoint(225, 350), wxSize(95,30)); pauppath->Enable(false); mrpath = new wxButton(mainPanel, mrpathBt, _("MrMT path") ,wxPoint(478, 350) ,wxSize(95,30)); mrpath ->Enable(false); #ifdef __WXMSW__ char line[1000]; modelpath->Enable(true); pauppath->Enable(true); //inNexus->Enable(true); //bayespath->Enable(true); mrpath->Enable(true); #endif saveScores = new wxButton(mainPanel, saveScBt, _("Save scores") ,wxPoint(16, 270) ,wxSize(95,30)); this->saveScores->Enable(false); saveScoresMr = new wxButton(mainPanel, saveScBtMr, _("Save scores") ,wxPoint(580, 230) ,wxSize(95,30)); this->saveScoresMr->Enable(false); help = new wxButton(mainPanel, helpMT, _("Help") ,wxPoint(16, 350) ,wxSize(95,30) ); outputText = new wxTextCtrl(mainPanel, outTxt, "" , wxPoint(120,20),wxSize(450,280) , wxVSCROLL | wxHSCROLL |wxTE_MULTILINE | wxTE_READONLY ); outputText->SetToolTip(wxT("Your results will be displayed here")); outputText->AppendText(_("Your result will be displayed here")); outputText->SetFont(wxFont(8, wxMODERN, wxNORMAL, wxNORMAL, FALSE, _T(""), wxFONTENCODING_SYSTEM)); //selectNexusStatic = new wxStaticText(mainPanel, ID_WXSTATICTEXT1 ," Select your PAUP result file clicking on the Select button.\ After running ModelTest, you can select your Nexus file to automatically include the resulting PAUP block by clicking on Edit Nexus File." ,wxPoint(16,10),wxSize(480,30)); #ifdef __WXMSW__ ifstream mpath("modelpath.ini"); ifstream mrpath("MrModelpath.ini"); ifstream ppath("pauppath.ini"); if(!mpath) { wxMessageBox("The path to ModelTest3* executable is not set.\nYou can do it by clicking the button MT path"); this->runModel->Enable(false); } else { mpath.getline(line, 1000); modelP = line; } mpath.close(); if(!mrpath) { wxMessageBox("The path to MrModelTest2.2 executable is not set.\nYou can do it by clicking the button MrMT path"); this->runMr->Enable(false); } else { mrpath.getline(line, 1000); mrModelP = line; } if(!ppath) { this->outputText->WriteText("\n\n\nThe path to PAUP is not set.\n You can do it by clicking the button PAUP path"); this->runPAUP->Enable(false); this->runBayes->Enable(false); } else { ppath.getline(line, 1000); paupP = line; ppath.getline(line, 1000); paupDir = line; } mpath.close(); mrpath.close(); ppath.close(); #endif }