frl::Bool copy( const frl::String &fileNameSrc, const frl::String &fileNameDst, frl::Bool overwrite ) { struct DescriptorManager { Descriptor fileSrc; Descriptor fileDst; DescriptorManager( void ) : fileSrc( InvalidDescriptor ), fileDst( InvalidDescriptor ) { } ~DescriptorManager( void ) { close( fileSrc ); close( fileDst ); } }; // struct DescriptorManger if( ! isExist( fileNameSrc ) ) return frl::False; if( isExist( fileNameDst ) && ( ! overwrite ) ) return frl::False; Stat stat_; if( ! getStat( fileNameSrc, stat_ ) ) return False; if( stat_.permissionMode & permDirectory ) return False; // FIXME mrdir implement! DescriptorManager dm; dm.fileSrc = open( fileNameSrc, openReadOnly ); if( dm.fileSrc == InvalidDescriptor ) return frl::False; dm.fileDst = open( fileNameDst, openCreate | openTruncate | openWriteOnly, stat_.permissionMode ); if( dm.fileDst == InvalidDescriptor ) return frl::False; frl::UChar buffer[4096]; RWCount readCount = InvalidRWCount; RWCount writeCount = InvalidRWCount; while( 1 ) { readCount = read( dm.fileSrc, buffer, sizeof(buffer) ); if( readCount < 0 ) return frl::False; if( readCount == 0 ) break; writeCount = write( dm.fileDst, buffer, readCount ); if( writeCount < 0) return frl::False; } return frl::True; }
void validate(char *str1, char *str2, char *str,int ar1[],int ar2[]){ int num1 = arrayToNumber(ar1, strlen(str1)); int num2 = arrayToNumber(ar2, strlen(str2)); int res = num1 + num2; int ar[strlen(str)]; int index1, index2; int p; // printf("%d + %d = %d\n",num1,num2,res); if(numberOfDigits(res) == strlen(str)){ numberToArray(ar, res); if(checkFinalString(str, ar)){ for(int i=0;i<strlen(str);i++){ index1 = isExist(str1,str[i]); index2 = isExist(str2,str[i]); // printf("str1: %s str2: %s ch: %c\n",str1, str2, str[i]); // printf("index1: %d index2: %d index: %d\n",index1, index2, index); if (index1!=-1) { if (ar1[index1] != ar[i]) { return; } } else{ for (p=0; p<strlen(str1); p++) { if (ar1[p] == ar[i]) { return; } } } if (index2!=-1) { if (ar2[index1] != ar[i]) { return; } } else{ for (p=0; p<strlen(str2); p++) { if (ar2[p] == ar[i]) { return; } } } } totalRes++; printf("%d + %d = %d \t",num1,num2, res); if (totalRes%2==0) { printf("\n"); } } } }
int CpList::addIfNot(CpHandler* pCP) { ACE_ASSERT(pCP); if(isExist(pCP)) return -1; //실제 사용시 get() 으로 중복 여부를 검사하고 add 하므로 여기서 다시 검사하지 않아도 된다. if(isExist(pCP->getHost(), pCP->getPort())) return -1; cpList.push_back(pCP); return 0; }
//Key GPIO number 26 bool getkey_gpio_26() { unsigned int value; FILE *pRreco = NULL; if(!isExist("/sys/class/gpio/gpio26")) { unsigned int value; FILE *pRreco = NULL; if((pRreco = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Open read gpio/export\n"); return -1; } if(fwrite("26", strlen("26"), 1, pRreco) != 1) printf("File Write Error!\n"); fclose(pRreco); } if((pRreco = fopen("/sys/class/gpio/gpio26/value","r")) == NULL) { printf("Open read recovery button failure\n"); return -1; } fscanf(pRreco,"%d",&value); fclose(pRreco); if(value) return true; else return false; }
int main() { int arr[10]; int mods[11]; for(int i=0;i<11;i++) { mods[i]=-1; } for(int i=0;i<10;i++) { scanf("%d",&arr[i]); } for(int i=0;i<10;i++) { int mod = arr[i]%42; if(!isExist(mods,mod)){ mods[len(mods)]=mod; } } printf("%d",len(mods)); return 0; }
void FileDir::create() { if( isExist() ) return; _OsCreate( *this ); }
std::map<Date, StockAccount> AccountManager::fetch(String codeName) const { return isExist(codeName) ? accountComponents_.find(codeName)->second : std::map<Date, StockAccount>(); }
//THIS MODULE WILL EXTRACT THE LINK FROM THE HTML TAG AND SAVE THE STRING INTO A CONTAINER string Crawler::getURL(string line) { //FINAL REGEX FOR EXTRACTING THE URL LINK FROM THE HTML TAG string reg = "<a\\s[^>]*href=\"([^\"]*)\"[^>]*>"; regex e(reg); smatch sm; string res; while (regex_search(line, sm, e)) { int i = 0; for (auto s : sm) { i++; if (i % 2 == 0&&!isExist(s)) { cout << s << endl; string st = s.str(); openList.push_back(new URLnode(st)); res = s; } else continue; } line = sm.suffix().str(); } int k = 0; return res; }
// 真ならば正しいパーミッションです。偽ならばメッセージも表示します。 bool checkAndPrintPermission() const { DEBUG_ASSERT(isExist()); if ((stat_.st_uid == 0) || (stat_.st_uid == euid_)) { if (stat_.st_mode & 0022) { SkkUtility::printf("illegal permission 0%o \"%s\"\n" "Try chmod go-w %s\n" , stat_.st_mode & 0777, filename_, filename_); return false; } } else { SkkUtility::printf("illegal owner \"%s\"\n" "file owner must be root or same euid\n" , filename_); return false; } return true; }
//------------------------------------------------------------------- bool IOSIOSystem::DeleteLocalFile( const std::string& strFileName ) { if( isExist(strFileName) ) { remove( strFileName.c_str() ); } return true; }
// 本名に対応するニックネームを取得する wxString CNickTable::getNickname(const wxString& name) { if (!isExist(name)){ return ""; } return (*this)[name]; }
SVIBool SVIAnimationSet::addAnimation(SVIAnimation* animation) { if( isExist(animation) ) return SVIFALSE; animation->setIsContainedInAniSet(SVITRUE); mAnimationList.push_back(animation); return SVITRUE; }
bool checkStringAssignment(char *str, int ar[]){ bool flag = true; int i; for (i=0; i<strlen(str); i++) { if(isExist(str,str[i]) != i){ if(ar[i] != ar[isExist(str,str[i])]){ flag = false; } }else{ for(int k=0;k<i;k++){ if(ar[i] == ar[k]){ flag = false; } } } } return flag; }
//Green light quickly Blink a few times, a buzzer rang a time int success_action() { if(!isExist("/sys/class/gpio/gpio20")) { unsigned int value; FILE *pRreco = NULL; if((pRreco = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Open read gpio/export\n"); return -1; } if(fwrite("20", strlen("20"), 1, pRreco) != 1) printf("File Write Error!\n"); fclose(pRreco); } if(!isExist("/sys/class/gpio/gpio45")) { unsigned int value; FILE *pRreco = NULL; if((pRreco = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Open read gpio/export\n"); return -1; } if(fwrite("45", strlen("45"), 1, pRreco) != 1) printf("File Write Error!\n"); fclose(pRreco); } int i; system("echo low > /sys/class/gpio/gpio20/direction"); system("echo 1 > /sys/class/gpio/gpio20/value"); usleep (200*1000); system("echo 0 > /sys/class/gpio/gpio20/value"); for(i=0;i<10;i++) { system("echo low >/sys/class/gpio/gpio45/direction"); usleep (200*1000); system("echo high >/sys/class/gpio/gpio45/direction"); } }
bool UserInfoText::isPassword(const string & userName, const string & password) { if (!isExist(userName)) return false; else { if (userPassword[userName] == password) return true; else return false; } }
bool CMUPCommon::deleteDir( std::string path ) { std::transform(path.begin(),path.end(),path.begin(), CMUPReplaceTag('/','\\')); if (!isExist(path)) { return true; } return (0 == ::_rmdir(path.c_str())); }
static bool u(const int& fd, const std::string& argu) { const std::string nargu = processArgument(argu); int chk = isExist(nargu); if (chk == -2) { fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str()); return false; } else if (chk == -1) { fprintf(stderr, "%s: Permission denied\n", nargu.c_str()); return false; } else if (chk == 0) { fprintf(stderr, "%s: No such file or directory\n", nargu.c_str()); return false; } else if (chk == 2) { fprintf(stderr, "%s is a directory\n", nargu.c_str()); return false; } else if (chk == 3) { fprintf(stderr, "%s is not a regular file\n", nargu.c_str()); return false; } FILE* fp = fopen(nargu.c_str(), "rb"); if (!fp) { fprintf(stderr, "%s: Unexpected Error\n", nargu.c_str()); return false; } unsigned long fileSize; struct stat st; stat(nargu.c_str(), &st); fileSize = st.st_size; char buffer[maxn]; cleanBuffer(buffer); sprintf(buffer, "u %s", argu.c_str()); birdWrite(fd, buffer); cleanBuffer(buffer); birdRead(fd, buffer); if (std::string(buffer) == "ERROR_OPEN_FILE") { fprintf(stderr, "Cannot open file \"%s\" on Remote Server\n", getFileName(argu.c_str()).c_str()); fclose(fp); return false; } printf("Upload File \"%s\"\n", getFileName(nargu).c_str()); cleanBuffer(buffer); sprintf(buffer, "filesize = %lu", fileSize); birdWrite(fd, buffer); printf("File size: %lu bytes\n", fileSize); birdWriteFile(fd, fp, fileSize); printf("Upload File \"%s\" Completed\n", getFileName(nargu).c_str()); fclose(fp); return true; }
void randCard(int *k) { int a,c; int i; for (i = 0; i < 10; i++) { do { c = (Random() * 20) + 8; //printf("a:%d, c:%d\n",a,c); } while (isExist(c,k)); k[i] = c; } }
bool FileUtils::createDirectory(const std::string& dirPath) { CCASSERT(!dirPath.empty(), "Invalid path"); if (isExist(dirPath) && isDirectory(dirPath)) return false; if (mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO) != 0) { CCLOGERROR("Create directory (%s) failed", dirPath.c_str()); } return true; }
//The Red light Blinking fast,continue 6s Red Light && buzzer int failure_action() { int i; if(!isExist("/sys/class/gpio/gpio20")) //To determine whether a file exists,nor,create { unsigned int value; FILE *pRreco = NULL; if((pRreco = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Open read gpio/export\n"); return -1; } if(fwrite("20", strlen("20"), 1, pRreco) != 1) printf("File Write Error!\n"); fclose(pRreco); } if(!isExist("/sys/class/gpio/gpio23")) { unsigned int value; FILE *pRreco = NULL; if((pRreco = fopen("/sys/class/gpio/export", "w")) == NULL) { printf("Open read gpio/export\n"); return -1; } if(fwrite("23", strlen("23"), 1, pRreco) != 1) printf("File Write Error!\n"); fclose(pRreco); } for(i=0;i<20;i++) { system("echo low > /sys/class/gpio/gpio20/direction"); system("echo 1 > /sys/class/gpio/gpio20/value"); system("echo low >/sys/class/gpio/gpio23/direction"); usleep (200*1000); system("echo high >/sys/class/gpio/gpio23/direction"); system("echo 0 > /sys/class/gpio/gpio20/value"); } }
bool DoublyLinkedList<T>::remove(T searchKey) { Node<T> *toBeDeleted; if (mCount == 0 || !isExist(searchKey)) { return false; } else { if (searchKey == mHead->mData) { toBeDeleted = mHead; if(mHead->mNext != NULL) { mHead = mHead->mNext; toBeDeleted->mNext = NULL; mHead->mPrevious = NULL; } delete toBeDeleted; } else if(searchKey == mTail->mData) { toBeDeleted = mTail; mTail->mPrevious->mNext = NULL; mTail = mTail->mPrevious; toBeDeleted->mPrevious = NULL; delete toBeDeleted; } else { toBeDeleted = mHead; while(toBeDeleted!= NULL && toBeDeleted->mData!= searchKey) { toBeDeleted = toBeDeleted->mNext; } toBeDeleted->mPrevious->mNext = toBeDeleted->mNext; toBeDeleted->mNext->mPrevious = toBeDeleted->mPrevious; toBeDeleted->mNext = NULL; toBeDeleted->mPrevious = NULL; delete toBeDeleted; } mCount--; return true; } }
void DungeonTest::removeDeadEnds() { bool done = false; while (!done) { done = true; for (int i = 0 ; i < _width ; i++) { for (int j = 0 ; j < _height ; j++) { //must corridors if (_blocks[i][j] <= _regionRoomMax) continue; int count = 0; if (!isExist(i+1,j) || isUnmade(i+1,j)) count ++; if (!isExist(i-1,j) || isUnmade(i-1,j)) count ++; if (!isExist(i,j+1) || isUnmade(i,j+1)) count ++; if (!isExist(i,j-1) || isUnmade(i,j-1)) count ++; if (count != 3) continue; done = false; _blocks[i][j] = BLOCK_BLANK; } } } }
bool Path::childPath(std::vector<std::string>& children) { if (!isExist()) { return false; } # ifdef WIN32 WIN32_FIND_DATAA findData; HANDLE handle = INVALID_HANDLE_VALUE; std::string path = _path + "\\*.*"; handle = FindFirstFile(path.c_str(), &findData); if (handle == INVALID_HANDLE_VALUE) { return false; } _path += '\\'; for (;;) { if (strcmp(findData.cFileName, ".") == 0 || strcmp(findData.cFileName, "..") == 0 ){ if (!FindNextFile(handle, &findData)) { break; } continue; } std::string path = _path + findData.cFileName; children.push_back(path); if (!FindNextFile(handle, &findData)) { break; } } # else DIR *dir = 0; struct dirent *ent = 0; dir = opendir(_path.c_str()); if (!dir) { return false; } _path += '/'; while (0 != (ent = readdir(dir))) { if (ent->d_type & DT_DIR) { if (strcmp(ent->d_name,".") == 0 || strcmp(ent->d_name,"..") == 0) { continue; } std::string path = _path + ent->d_name; children.push_back(path); } } # endif // WIN32 return true; }
bool deleteData(POIDataPtr poi_data_ptr) { assert(poi_set != NULL); assert(!isExist(poi_data_ptr)); POISet::iterator it = poi_set->find(poi_data_ptr); if (it != poi_set->end()) { (*it)->leaf_node = NULL; poi_set->erase(it); return true; } return false; }
bool BankCardText::isPassword(const string & number, const string & password) { if (!isExist(number)) return false; else { istringstream line(bankCardMap[number]); string num, pass; line >> num >> pass; if (pass == password) return true; else return false; } }
static gboolean addToList(MimeTypeElement **typelist, PluginInstance *This) { if (This && This->type && !isExist(typelist, This->type)) { MimeTypeElement *ele; if ((ele = (MimeTypeElement *) NPN_MemAlloc(sizeof(MimeTypeElement)))) { ele->pinst = This; ele->next = *typelist; *typelist = ele; return(TRUE); } } return(FALSE); }
int editor(const int fd_in,const int fd_out){ int out; // catch command cmd_t cmd = catch_cmd(); while(isExist(cmd)){ /* execute commande (read fdin) in -> new_in * offset is increment and never decrement * if offset in end-file cmd finish * catch new cmd */ out = exec_cmd(cmd, fd_in); cmd_t cmd = catch_cmd(); } // when finish write out to fdout return EXIT_SUCCESS; }
FilePath FilePath::getUpDir() const { if( !_d->path.size() ) return ""; FilePath pathToAny = removeEndSlash(); std::string::size_type index = pathToAny._d->path.find_last_of( "/" ); if( index != std::string::npos ) { return FilePath( pathToAny._d->path.substr( 0, index ) ); } _OC3_DEBUG_BREAK_IF( !isExist() ); return ""; }
void average_fixed_pos_E_KSDC(u32 d,u32 num_ISD){ double average_E_KSDC_pos_num=0.0; for(int D=1;D<=num_ISD;D++){ //randomly induce the differences to d positions. NFSR:0~79,LFSR:80~159 u32* pos=new u32[d](); for(int j=0;j<d;j++){ //pos[j]=rc4() % 160; //pos[j]=(rc4() % 80)+80; //只给LFSR中引入差分 //pos[j]=(rc4() % 80); //只给NFSR中引入差分 //pos[j]=(rc4() % 40)+80; //只給LFSR的左半部分引入差分 80-119 pos[j]=(rc4() % 40)+120; //只给LFSR的右半部分引入差分 120-159 while(isExist(pos,j,pos[j])) //to ensure the non-duplicated positions //pos[j]=rc4() % 160; //pos[j]=(rc4() % 80)+80; //只给LFSR中引入差分 //pos[j]=(rc4() % 80); //只给NFSR中引入差分 //pos[j]=(rc4() % 40)+80; //只給LFSR的左半部分引入差分 80-119 pos[j]=(rc4() % 40)+120; //只给LFSR的右半部分引入差分 120-159 } // induce the differece to selected position u8 ISD[LEN]; for(int j=0;j<LEN;j++){ ISD[j]=0; } for(int j=0;j<d;j++){ u32 p=posIdx(pos[j]); u32 r=rotateIdx(pos[j]); ISD[p]=ISD[p]^(1<<r); } // generate E-KSDC and record the number of fixed positions ECRYPT_ctx ctx; ctx.keysize=80; ctx.ivsize=64; ECRYPT_grain_state_load(&ctx,ISD); u8 E_KSDC_Array[KSLen*8]; for(int j=0;j<KSLen*8;j++){ E_KSDC_Array[j]=ENCRYPT_grain_E_KSDC(&ctx); if(E_KSDC_Array[j]<2) average_E_KSDC_pos_num++; } } average_E_KSDC_pos_num=(double)average_E_KSDC_pos_num/num_ISD; cout<<"The average fixed pos(d,l):(" <<d<<","<<KSLen*8<<",) is "<<setprecision(3)<<average_E_KSDC_pos_num<<endl; }
void SkpFileWidget::onPush(SkpTransferFile *transferFile, qint32 status) { int row = -1; int serverStatus = FileDataStatusPushing; if(status == PushRstStatusExist) { row = isExist(transferFile->m_path, transferFile->m_md5, FileStatusCheckServer); } if(status == PushRstStatusRequest || status == PushRstStatusStartPush || status == PushRstStatusPushing || status == PushRstStatusRate || status == PushRstStatusStop || status == PushRstStatusError || status == PushRstStatusSuccess) { row = isExistMD5(transferFile->m_md5); } if(status == PushRstStatusSuccess) { serverStatus = FileDataStatusFinish; } if(row >= 0) { SkpFileData_t *fileData = (SkpFileData_t *)getRowData(row); fileData->serverStatus = serverStatus; fileData->clientStatus = status; fileData->offset = transferFile->m_offset; fileData->rateByte = transferFile->m_lastRatebytes; fileData->proportion = SkpUtility::proportion(transferFile->m_requestDataSize, transferFile->m_fileSize); updateRowData(row); } if(status == PushRstStatusExist) { selectAndShowRow(row); } if(status == PushRstStatusExist || status == PushRstStatusSuccess) { transferFile->deleteLater(); } }