// from: http://msdn.microsoft.com/en-us/library/ms724235(VS.85).aspx bool Registry::rdel(HKEY hKeyRoot, LPTSTR lpSubKey) { logger->debug(L"Registry::rdel -> " + wstring(lpSubKey)); LPTSTR lpEnd = nullptr; LONG result; DWORD size; TCHAR szName[MAX_PATH * 2] = { 0 }; HKEY hKey; FILETIME ftWrite; // First, see if we can delete the key without having to recurse. result = ::RegDeleteKey(hKeyRoot, lpSubKey); if (result == ERROR_SUCCESS) return true; result = ::RegOpenKeyEx(hKeyRoot, lpSubKey, 0, KEY_READ, &hKey); if (result == ERROR_FILE_NOT_FOUND) { return true; } else if (result != ERROR_SUCCESS) { logger->debug(L"Registry::rdel error opening key"); return false; } // Check for an ending slash and add one if it is missing. lpEnd = lpSubKey + lstrlen(lpSubKey); if (*(lpEnd - 1) != TEXT('\\')) { *lpEnd = TEXT('\\'); lpEnd++; *lpEnd = TEXT('\0'); } // Enumerate the keys size = MAX_PATH; result = ::RegEnumKeyEx(hKey, 0, szName, &size, NULL, NULL, NULL, &ftWrite); if (result == ERROR_SUCCESS) { do { StringCchCopy(lpEnd, MAX_PATH * 2, szName); if (!rdel(hKeyRoot, lpSubKey)) { break; } size = MAX_PATH; result = ::RegEnumKeyEx(hKey, 0, szName, &size, NULL, NULL, NULL, &ftWrite); } while (result == ERROR_SUCCESS); } lpEnd--; *lpEnd = TEXT('\0'); ::RegCloseKey(hKey); // Try again to delete the key. result = ::RegDeleteKey(hKeyRoot, lpSubKey); return result == ERROR_SUCCESS; }
bool Registry::del() { logger->debug(L"Registry::del -> " + boost::lexical_cast<wstring>(this->root) + L" -> " + subkey); if (!open()) return false; TCHAR buf[MAX_PATH * 2] = { 0 }; StringCchCopy(buf, MAX_PATH * 2, subkey.c_str()); return rdel(root, buf) != FALSE; }
bool ReplicaExchange::do_exchange(double myscore0, double myscore1, int findex) { double myscore=myscore0-myscore1; double fscore; int myindex=index_[myrank_]; int frank=get_rank(findex); MPI_Sendrecv(&myscore,1,MPI_DOUBLE,frank,myrank_, &fscore,1,MPI_DOUBLE,frank,frank, MPI_COMM_WORLD, &status_); bool do_accept=get_acceptance(myscore,fscore); boost::scoped_array<int> sdel(new int[nproc_ - 1]); boost::scoped_array<int> rdel(new int[nproc_ - 1]); for(int i=0;i<nproc_-1;++i) {sdel[i]=0;} if(do_accept){ std::map<std::string,Floats>::iterator it; for (it = parameters_.begin(); it != parameters_.end(); it++){ Floats param = get_friend_parameter((*it).first,findex); set_my_parameter((*it).first,param); } //update the increment vector only to those replicas that upgraded to //a higher temperature to avoid double // calculations (excluding the transition 0 -> nrep-1) int delindex=findex-myindex; if (delindex==1){ //std::cout << myindex << " " << findex << " " << std::endl; sdel[myindex]=1; } //update the indexes myindex=findex; } MPI_Barrier(MPI_COMM_WORLD); //get the increment vector from all replicas and copy it to the //exchange array MPI_Allreduce(sdel.get(),rdel.get(),nproc_-1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); for(int i=0;i<nproc_-1;++i) {exarray_[i]=rdel[i];} // in any case, update index vector boost::scoped_array<int> sbuf(new int[nproc_]); boost::scoped_array<int> rbuf(new int[nproc_]); for(int i=0;i<nproc_;++i) {sbuf[i]=0;} sbuf[myrank_]=myindex; MPI_Allreduce(sbuf.get(),rbuf.get(),nproc_,MPI_INT,MPI_SUM,MPI_COMM_WORLD); for(int i=0;i<nproc_;++i){index_[i]=rbuf[i];} return do_accept; }
void rdel(char *path, Boolean rm_only_dirs) { DIR *dir; struct dirent *entry; struct stat stats; int i, pl = strlen(path), res; if (abort_delete || lstat(path, &stats) || !(dir = opendir(path))) return; if (!(permission(&stats, P_WRITE))) { closedir(dir); errno = EPERM; rmError(path, !rm_only_dirs); return; } for (i=0; (entry = readdir(dir)); i++) { if (entry->d_name[0] != '.' || (entry->d_name[1] != '\0' && (entry->d_name[1] != '.' || entry->d_name[2] != '\0'))) { int pl1 = pl, l = strlen(entry->d_name); char *path1 = (char *)alloca(pl1+l+2); strcpy(path1, path); if (path1[pl1-1] != '/') path1[pl1++] = '/'; strcpy(path1+pl1, entry->d_name); if (!(res = lstat(path1, &stats))) { if (!S_ISLNK(stats.st_mode) && S_ISDIR(stats.st_mode)) rdel(path1, rm_only_dirs); else if (!rm_only_dirs) res = unlink(path1); } if (res) { rmError(path1, !rm_only_dirs); if (abort_delete) break; } } } if (closedir(dir) || rmdir(path)) rmError(path, !rm_only_dirs); }
int btree::rdel(btnode **pn) { if(pn != NULL) { rval = 1; btnode *temp = *pn; if(temp->ltree == NULL) // twig/leaf may have right tree { *pn = temp->rtree; // set current p2p to right tree delete temp; // deallocate } else if(temp->rtree == NULL) // twig/leaf may have left tree { *pn = temp->ltree; // set current p2p to left tree delete temp; // deallocate } else // branch { if(toggle++) { pn = &((*pn)->rtree); // move one right while((*pn)->ltree != NULL) // move left till end pn = &((*pn)->ltree); } else { pn = &((*pn)->ltree); // move one left while((*pn)->rtree != NULL) // move right till end pn = &((*pn)->rtree); } temp->data = (*pn)->data; // set data rdel(pn); // delete twig/leaf } } else rval = 0; return rval; }
void deleteDirProc(XtPointer fsel, int conf) { SelFileNamesRec *fnames = (SelFileNamesRec *) fsel; switch (conf) { case CANCEL: fnames->first = fnames->n_sel; break; case YES: if (chdir(fnames->directory)) sysError(fnames->shell, "System error:"); else { rdel(fnames->names[fnames->first], False); chdir(user.home); fnames->update = True; } case NO: fnames->first++; } deleteFilesProc(fsel, YES); }
int rdel(char *path) { struct stat stats; if (lstat(path, &stats)) return -1; if (S_ISDIR(stats.st_mode)) { DIR *dir; struct dirent *entry; int i, pl = strlen(path); if (!(dir = opendir(path))) return -1; for(i = 0; (entry = readdir(dir)); i++) if (entry->d_name[0] != '.' || (entry->d_name[1] != '\0' && (entry->d_name[1] != '.' || entry->d_name[2] != '\0'))) { int pl1 = pl, l = strlen(entry->d_name); char *path1 = (char *)alloca(pl1+l+2); strcpy(path1, path); if (path1[pl1-1] != '/') path1[pl1++] = '/'; strcpy(path1+pl1, entry->d_name); if (rdel(path1)) { /* take care of recursive errors */ char s[0xff]; sprintf(s, "Error deleting %s:", path); sysError(s); } } if (closedir(dir)) return -1; else return rmdir(path); } else return unlink(path); }
void rmDirs(char *path) { abort_delete = False; rdel(path, True); }
void rdelete(char *path) { abort_delete = False; rdel(path, False); }
int btree::del(float d) { return rdel( rfind(entry, d) ); }