char * mystrcat(char * dest, char * src) { int lengthDest = mystrlen(dest); int lengthSrc = mystrlen(src); int i; if (lengthSrc == 0) return dest; for (i = lengthDest; i < lengthDest + lengthSrc; i++) { dest[i] = src[i - lengthDest]; } return dest; }
/* sava_data bin (C->S) */ EdpPacket* PacketSavedataBin(const char* dst_devid, cJSON* desc_obj, uint8* bin_data, uint32 bin_len) { EdpPacket* pkg; uint32 remainlen; /* check arguments */ char* desc_out = cJSON_Print(desc_obj); uint32 desc_len = mystrlen(desc_out); if (desc_len > (0x01 << 16) || bin_len > (3 * (0x01 << 20)) /* desc < 2^16 && bin_len < 3M*/ || cJSON_GetObjectItem(desc_obj, "ds_id") == 0) /* desc_obj MUST has ds_id */ { hx_free(desc_out); return 0; } pkg = NewBuffer(); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1+(2+mystrlen(dst_devid))+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* bin flag */ WriteByte(pkg, 0x02); /* desc */ WriteStr(pkg, desc_out); hx_free(desc_out); /* bin data */ WriteUint32(pkg, bin_len); WriteBytes(pkg, bin_data, bin_len); return pkg; }
int main(void) { char *str = "hello"; int len = mystrlen(str); printf("len = %d\n", len); str = "hello world"; len = mystrlen(str); printf("len = %d\n", len); return 0; }
//------------------------------------------------------------------------- void strappend(char *base, char *string) { int length1, length2; uint8_t i; length1 = mystrlen(base); length2 = mystrlen(string); for (i = 0; i < length2; i++) { base[i + length1] = string[i]; } base[length1 + length2] = '\0'; }
char *mystrcat(char * s1, const char * s2) { int len1 = mystrlen(s1); int len2 = mystrlen(s2); int i; for (i = 0; i < (len2 + 1); i++) { s1[len1 + i] = s2[i]; } return s1; }
int mystrcmp(char * s1, char * s2) { int temp1 = mystrlen(s1); int temp2 = mystrlen(s2); if(temp1-temp2 == 0) { return 0; } if(temp1 - temp2 > 0){ return 1; } if (temp1 - temp2 < 0) { return -1; } }
char * mystrcpy(char * dest, char * src) { int length = mystrlen(src); int destLength = mystrlen(dest); int i; if (length == 0) { for (i = 0; i < destLength; i++) dest[i] = NULL; } for (i = 0; i < length; i++) { dest[i] = src[i]; } return dest; }
char * mystrcat(char * dest, char * src) { int i = 0; int j = mystrlen(dest); while (i < mystrlen(src)) { dest[j] = src[i]; i++; j++; } dest[j] = '\0'; return dest; }
int mystrngcasecmp (const char *strng1ptr, const char *strng2ptr) { char *str1, *str2; int answer = 0; int size1, size2; // length of each string; int counto; // counts to value of variable int counter; // used in for loop. str1 = strng1ptr; str2 = strng2ptr; size1 = mystrlen(str1); size2 = mystrlen(str2); if (size1 > size2) counto = size1; if (size1 <= size2) counto = size2; for (counter = 0; counter <= counto; counter++) { if (*(str1 + counter) >96 && *(str1 + counter) < 123) *(str1 + counter) -= 32; if (*(str2 + counter) > 96 && *(str2 + counter) < 123) *(str2 + counter) -= 32; } for ( counter = 0; counter <= counto; counter++) { if (str1[counter] > str2[counter]) { answer = 1; break; } if (str2[counter] > str1[counter]) { answer = -1; break; } if (str1[counter] == '\0' && str2[counter] == '\0') { answer = 0; break; } } return(answer); }
int mystrcmp(char * s1, char * s2) { int length1 = mystrlen(s1); int length2 = mystrlen(s2); int i; if (length1 > length2) return 1; if (length2 > length1) return -1; for (i = 0; i < length1; i++) { if (s1[0] != s2[0]) return -1; } return 0; }
int mystrcmp(char * s1, char * s2) { int a = mystrlen(s1); int b = mystrlen(s2); if(a==b) { return 0; } else if(a>b) { return 1; } else return -1; }
int strend(char *s, char *t) { int sl = mystrlen(s); int tl = mystrlen(t); char *ps = s + sl - 1; char *pt = t + tl - 1; while (pt - t >= 0 && *pt == *ps) { if (pt - t == 0) { return 1; } pt--; ps--; } return 0; }
static int show_error(const wchar_t *preamble, const wchar_t *msg, const int code) { wchar_t *buf; buf = (wchar_t*)LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t)* (mystrlen(msg) + mystrlen(preamble) + 80)); if (!buf) { MessageBox(NULL, preamble, NULL, MB_OK|MB_ICONERROR); return code; } MessageBeep(MB_ICONERROR); wsprintf(buf, L"%s\r\n %s (Error Code: %d)\r\n", preamble, msg, code); MessageBox(NULL, buf, NULL, MB_OK|MB_ICONERROR); LocalFree(buf); return code; }
int mystrcspn(char s[], char t[]) { int i, j, m, n; n = mystrlen(s); m = mystrlen(t); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { /*2 for-a zbog dve niske */ if (s[i] == t[j]) { return i; } } } return -1; }
int main(void) { printf("mystrlen():%d\n", mystrlen("good afternoon")); printf("strlen():%d\n", strlen("good afternoon")); return 0; }
static void NSISCALL SetSizeText(int dlgItem, int prefix, unsigned kb) { TCHAR scalestr[32], byte[32]; unsigned sh = 20; int scale = LANG_GIGA; if (kb < 1024 * 1024) { sh = 10; scale = LANG_MEGA; } if (kb < 1024) { sh = 0; scale = LANG_KILO; } if (kb < (0xFFFFFFFF - ((1 << 20) / 20))) // check for overflow kb += (1 << sh) / 20; // round numbers for better display (e.g. 1.59 => 1.6) wsprintf( GetNSISString(g_tmp, prefix) + mystrlen(g_tmp), TEXT("%u.%u%s%s"), kb >> sh, (((kb & 0x00FFFFFF) * 10) >> sh) % 10, // 0x00FFFFFF mask is used to // prevent overflow that causes // bad results GetNSISString(scalestr, scale), GetNSISString(byte, LANG_BYTE) ); my_SetDialogItemText(m_curwnd,dlgItem,g_tmp); }
DWORD CALLBACK StreamLicense(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { lstrcpyn((TCHAR *)pbBuff,(TCHAR*)dwCookie+dwRead,cb); *pcb=mystrlen((TCHAR *)pbBuff); dwRead+=*pcb; return 0; }
//------------------------------------------------------------------------- void reply_ps(uint8_t * receivebuffer) { uint8_t i, len; //reply[0] = 15; reply[1] = 171; reply[2] = nodeid; for (i = 0; i < LITE_MAX_THREADS; i++) { if (thread_table[i].state != STATE_NULL) { len = mystrlen((char *)thread_table[i].threadName); reply[0] = len + 4; reply[3] = thread_table[i].state; //if this is a break thread, then fetch the real number if (reply[3] == STATE_BREAK) { uint8_t *tempptr = (uint8_t *) thread_table[i].sp + 47; uint16_t addr = (((uint16_t) (*tempptr)) * 256 + *(tempptr + 1) - 3); reply[4] = addr / 256; reply[5] = addr % 256; reply[0] += 2; mystrncpy((char *)&reply[6], (char *)thread_table[i].threadName, len); } else { mystrncpy((char *)&reply[4], (char *)thread_table[i].threadName, len); } StandardSocketSend(0xefef, 0xffff, 32, reply); } } }
size_t mystrlen(char *s){ if (s[0]){ return 1 + mystrlen(s+1); }else{ return 0; } }
int myatoi(const char *p) { const char *tmp = NULL; int status = 0;//0代表正数,1代表负数 if (*p == '-') { status = 1; tmp = p + 1;//会从第二个字符开始转化 } else if (*p == '+') { tmp = p + 1; } else { tmp = p; } int len = mystrlen(tmp); int value = 0; int i; for(i = 0; i < len; i++) { value += (tmp[i] - '0') * pow_10(len - i - 1); } if (status == 0) return value; else return -value; }
/* Parse a line for a template. Result should be freed via FreeTemplate() */ APTR ParseTemplate(CONST_STRPTR temp, STRPTR line, APTR results) { ULONG *mem = (ULONG*)AllocVec(12,0); if(mem) { struct RDArgs *rdargs = (struct RDArgs*)AllocDosObject(DOS_RDARGS,NULL); if((mem[0] = (ULONG)rdargs)) { LONG len = mystrlen(line)+2; STRPTR buf = (STRPTR)AllocVec(len,0); if((mem[1] = (ULONG)buf)) { struct RDArgs *rd; if (line) strcpy(buf,line); buf[len-2]=10; buf[len-1]=0; rdargs->RDA_Buffer = NULL; rdargs->RDA_Source.CS_Buffer = (UBYTE *)buf; rdargs->RDA_Source.CS_Length = strlen(buf); rdargs->RDA_Source.CS_CurChr = 0; rd = ReadArgs(temp,(LONG*)results, rdargs ); if((mem[2] = (ULONG)rd)) { return mem; } } } } FreeTemplate(mem); return NULL; }
/** *\fn int mysnprintf (char *str, size_t size, const char *format,...) *\brief wrapper pour la fonction snprintf *\param str : tableau de caractere contenant la chaine formatee *\param size : taille de la chaine str *\param format : liste d'arguments *\return : nombre de caracteres copies dans str sans compter le \\0 final ou qui auraient du etre copies si la chaine avait ete assez longue */ int mysnprintf (char *str, size_t size, const char *format,...) { va_list ap; int returnval =0; #ifdef PREDEF_STANDARD_C_1999 va_start(ap, format); returnval= vsnprintf(str,size,format,ap); va_end(ap); return returnval; #else const size_t len_format=mystrlen(format)+1; char *newformat = allocArray1D(len_format,sizeof(*newformat)); va_start(ap, format); changeFormat(newformat,format, len_format); if (len_format>size) { va_end(ap); str[0]='\0'; freeArray1D(newformat),newformat=NULL; return -1; } returnval=vsprintf(str,newformat,ap); freeArray1D(newformat),newformat=NULL; va_end (ap); return returnval; #endif }
char *mystrdup(const char *s1) { int len = mystrlen(s1) + 1; void *new = malloc(len); return mystrcpy(new, s1); }
struct MidiCluster *NewCluster(char *name,struct CamdBase *CamdBase){ struct MyMidiCluster *mymidicluster; struct MidiCluster *midicluster; mymidicluster=AllocMem(sizeof(struct MyMidiCluster),MEMF_ANY | MEMF_CLEAR | MEMF_PUBLIC); if(mymidicluster==NULL) return NULL; InitSemaphore(&mymidicluster->semaphore); midicluster=&mymidicluster->cluster; midicluster->mcl_Node.ln_Name=AllocVec(mystrlen(name) + 1,MEMF_ANY|MEMF_PUBLIC); if(midicluster->mcl_Node.ln_Name==NULL){ FreeMem(midicluster,sizeof(struct MyMidiCluster)); return NULL; } mysprintf(CamdBase,midicluster->mcl_Node.ln_Name,"%s",name); NEWLIST(&midicluster->mcl_Receivers); NEWLIST(&midicluster->mcl_Senders); AddTail(&CB(CamdBase)->midiclusters,&midicluster->mcl_Node); return midicluster; }
/** *\fn int myprintf(const char *format,...) *\brief wrapper pour la fonction printf *\param format : chaine de formatage *\param ... : liste d'arguments *\return : nombre de caracteres ecrits */ int myprintf(const char *format,...) { const size_t len_format=mystrlen(format)+1; int returnval =0; va_list ap; va_start(ap, format); #ifdef PREDEF_STANDARD_C_1999 returnval= vfprintf(stdout,format,ap); va_end (ap); return returnval; #else /*recherche des indicateurs de "size_t" et on les convertit*/ { char *newformat = allocArray1D(len_format,sizeof(*newformat)); changeFormat(newformat,format, len_format); returnval=vfprintf(stdout,newformat,ap); freeArray1D(newformat),newformat=NULL; va_end (ap); return returnval; } #endif }
std::string Server::getDaemonInfo( void ) { std::string info; static const char *cmds[][100] = SERV_CMDS; info = "Daemon written by GBOURGEO for 42."; info += "\n"; info += "Daemon started on "; info += ctime(&this->start_time); info += "Daemon max. clients: " + std::to_string(SERV_MAX_CLIENTS) + "\n"; info += "Daemon curr. clients: " + std::to_string(this->nb_clients) + "\n"; info += "Daemon encrypted version : "; info += (this->encrypt) ? "Yes" : "No"; info += "\n"; info += "Daemon passwd protected : "; info += (this->protect) ? "Yes" : "No"; info += "\n"; info += "Daemon passwd: \""; info += this->passwd.c_str(); info += "\"\n"; info += "Daemon commands available :"; for (int i = 0; cmds[i][0]; i++) { info += "\n- \""; info += cmds[i][0]; info += "\"\t"; if (mystrlen(cmds[i][0]) <= 9) info += "\t"; info += cmds[i][1]; } info += "\n"; return info; }
int main(){ int len = mystrlen(TEST_STRING); int fd = open(TEST_FILE, O_RDWR|O_TRUNC, 0); if(fd == -1) return 1; char buffer[30] = {0}; int i = 0; for(i = 0; i < 1000; i++){ /* if(i % 10 == 0){ fast_itoa(i, buffer); print("\nProcess 1: "); print(buffer); } */ if(write(fd, TEST_STRING, len) != len){ close(fd); return 2; } } close(fd); return 0; }
void addNode(BinSTreeNode *rootNode, BinSTreeNode *node) { if (node == NULL) { return; } if (rootNode->str == NULL) { /* rootNode is empty! */ rootNode->str = (char*)malloc(sizeof(char)*(mystrlen(node->str)+1)); mystrcpy(rootNode->str, node->str); setNodeAsLeft(rootNode, node->left); setNodeAsRight(rootNode, node->right); node->left = NULL; node->right = NULL; deleteNode(node); } else { /* Normal addNode() */ if (isLeft(rootNode, node)) { /* node should be left of root */ if (rootNode->left == NULL) { /* There is no left child */ setNodeAsLeft(rootNode, node); if(DEBUG) printf("Add %s <- [%s%s%s]\n", node->str, CYAN, rootNode->str, DEFAULT); } else { /* search for left edge */ addNode(rootNode->left, node); } } else { /* root <= node */ if (rootNode->right == NULL) { /* There is no right child */ setNodeAsRight(rootNode, node); if(DEBUG) printf("Add [%s%s%s] -> %s\n", CYAN, rootNode->str, DEFAULT, node->str); } else { /* search for left edge */ addNode(rootNode->right, node); } } } return; }
void send_task() { struct msgData *dataPayloadPtr_currentMsg; dataPayloadPtr_currentMsg = (struct msgData *)currentMsg.data; if (radiosocketdata.socket_msg_len == 0) { radiosocketdata.socket_msg_len = mystrlen((char *)radiosocketdata.socket_msg); } mystrncpy((char *)dataPayloadPtr_currentMsg, (char *)radiosocketdata.socket_msg, radiosocketdata.socket_msg_len); if (radiosocketdata.socket_addr != 0) { AMStandard_SendMsg_send(radiosocketdata.socket_port, radiosocketdata.socket_addr, radiosocketdata.socket_msg_len, ¤tMsg); } else { currentMsg.length = radiosocketdata.socket_msg_len; currentMsg.addr = radiosocketdata.socket_addr; currentMsg.port = radiosocketdata.socket_port; currentMsg.strength = 0; currentMsg.lqi = 0; Standard_Receive_Packet(radiosocketdata.socket_port, ¤tMsg); } //#endif }
void right(char *d,char *s,int n) { int i,ld,ls; char *d2; d2=d; ls=mystrlen(s); ld=mystrlen(d); for(i=0;i<ld+1;i++){ *d2='\0'; d2+=sizeof(char); } if(ls-n<0) n=ls; for(i=0;i<n;i++){ *(d+i*sizeof(char))=*(s+(ls-n+i)*sizeof(char)); } }