nmap中字符串添加的功能函数
/* Prepend an n-char string to a filespace */
int fs_prepend(char *str, int len, struct filespace *fs){
char *tmpstr;
if (len < 0)
return -1;
if (len == 0)
return 0;
if (fs->current_alloc - fs->current_size < len + 2) {//这里判断是否有足够空间放str
fs->current_alloc = (int)(fs->current_alloc * 1.4 + 1);//不明白为什么×1.4
fs->current_alloc += 100 + len;
tmpstr = (char *)safe_malloc(fs->current_alloc);
memcpy(tmpstr, fs->str, fs->current_size);//将原有的字符串复制到新开辟的内存中
fs->pos = (fs->pos - fs->str) + tmpstr;//修改pos的位置,假如pos和str在同一个位置上,就是把tmpstr赋值给了pos,如果不在一个位置上,就不懂了
if (fs->str)
free(fs->str);
fs->str = tmpstr;
}
if (fs->current_size > 0)
memmove(fs->str + len, fs->str, fs->current_size);//后移len
memcpy(fs->str, str, len);
fs->current_