⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aff_toc.cpp

📁 sleuthit-2.09 一个磁盘的工具集
💻 CPP
字号:
/* * afflib_dir.cpp: *  * Functions for the manipulation of the AFF directories */#include "config.h"#include "afflib.h"#include "afflib_i.h"int	af_toc_free(AFFILE *af){    if(af->toc){	for(int i=0;i<af->toc_count;i++){	    if(af->toc[i].name) free(af->toc[i].name);	}	free(af->toc);	af->toc = 0;	af->toc_count = 0;    }    return 0;}void	af_toc_print(AFFILE *af){    printf("AF DIRECTORY:\n");    for(int i=0;i<af->toc_count;i++){	if(af->toc[i].name){	    printf("%-32s %" I64d " \n",af->toc[i].name, af->toc[i].offset);	}    }}int	af_toc_append(AFFILE *af,const char *segname,int64 offset){    af->toc = (af_toc_mem *)realloc(af->toc,sizeof(*af->toc)*(af->toc_count+1));    if(af->toc==0){	(*af->error_reporter)("realloc() failed in af_toc_append. toc_count=%d\n",af->toc_count);	return -1;    }    af->toc[af->toc_count].offset = offset;    af->toc[af->toc_count].name = strdup(segname); // make a copy of the string    af->toc_count++;    return 0;}/* * af_toc_build: * Build the directory by reading the existing file... */int	af_toc_build(AFFILE *af)	// build the dir if we couldn't find it{    af_toc_free(af);    af_rewind_seg(af);			// start at the beginning    // note: was malloc(0), but that causes problems under Borland        af->toc = (af_toc_mem *)malloc(sizeof(af_toc_mem));    while(1){	char segname[AF_MAX_NAME_LEN];	size_t segname_len=sizeof(segname);	int64 pos = ftello(af->aseg);	if(af_get_next_seg(af,segname,segname_len,0,0,0)!=0) break;	if(af_toc_append(af,segname,pos)){	    af->disable_toc = 1;	    return -1; // malloc error?	}    }    return 0;}/* * return the named entry in the directory */struct af_toc_mem *af_toc(AFFILE *af,const char *segname){    if(af->toc){	for(int i=0;i<af->toc_count;i++){	    if(af->toc[i].name && strcmp(af->toc[i].name,segname)==0) return &af->toc[i];	}    }    return 0;}/* Delete something from the directory, but don't bother reallocating.*/void af_toc_del(AFFILE *af,const char *segname){    if(af->toc){	for(int i=0;i<af->toc_count;i++){	    if(strcmp(af->toc[i].name,segname)==0){		free(af->toc[i].name);		af->toc[i].name=0;		return;	    }	}    }}void af_toc_insert(AFFILE *af,const char *segname,int64 offset){    if(af->toc){	for(int i=0;i<af->toc_count;i++){	    if(af->toc[i].name==0 || strcmp(af->toc[i].name,segname)==0){		if(af->toc[i].name==0){	// if name was empty, copy it over		    af->toc[i].name = strdup(segname);		}		af->toc[i].offset = offset;		return;	    }	}	/* Need to append it to the directory */	af_toc_append(af,segname,offset);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -