Hi all,I am facing problem with the memcpy function while copying
for (i = 0; i <= ((128*1024)-len); i++) {
if (memcmp(buf + i, search_data,len) == 0) {
memcpy(buf + i, &replace_data, len);
}
}
Upto some value the data is copying then the memcmp function fails.I dnt know why…?
buf is char pointer and search_data and replace_data char array of len-32.
here the len is 8.
Anything wrong in this ,please advice
Here is the code:
=====================================================
void update(char `*`device,unsigned long pos)
{
char search_str[MAX_LEN]="", replace_str[MAX_LEN]="";
unsigned char search_data[32]="ffbff9e0", replace_data[32]="ffbff9c0";
unsigned long i;
FILE `*`fp;
char `*`buf;
fp=fopen(device,"rb+");
fseek(fp, pos, SEEK_SET);
buf=(char `*`)calloc(1, (128 `*` 1024));
fread(buf,(128 `*` 1024),1,fp);
for (i = 0; i <= ((128 * 1024) - strlen(search_data)); i++)
{
if (memcmp(buf + i, search_data, strlen(search_data)) == 0)
{
memcpy(buf + i, &replace_data, strlen(search_data));
}
}
fseek(fp, pos, SEEK_SET);
fwrite(buf, (128 * 1024), 1, fp);
fclose(fp);
free(buf);
}