我需要帮助来了解一些旧的 C 代码中发生了什么。
我正在使用旧的 btree/isam 软件产品(来自 Softfocus)将我的数据写入数据库。它本质上将数据放入mydb.dt
文件中,并将索引数据放入mydb.nx
(例如)。
在我的程序中,我有一个结构,其成员对应于数据库中的“字段”。结构是这样定义的(我用虚构的数据大大简化了):
typedef struct {
unsigned char name[50]; /*size is 50 bytes*/
int active; /*size is 4 bytes*/
int yet_unused_bytes[46]; /*unused space (in fixed-length record)*/
} DB_PEOPLE; /*total struct size is 100 bytes*/
当我想写入记录时,我bt3Write
像这样调用数据库软件的例程(people_db_fd
是我的数据库文件的描述符,db_current_record_people
只是我上面的结构的副本,其中包含数据):
ret = bt3Write(people_db_fd, db_current_record_people);
该bt3Write
例程基本上如下(我认为确切知道它在做什么并不重要,但关键部分是 trueBase 位)。是fd
数据库文件,data
是字节流(db_current_record_people
我在上面交给它的结构)。我想recno
这只是我在这里不关心的 nx 文件的一些开销,它lioWrite
负责:
/*
* all the keys are in; write the data record and store a copy
*/
if (lioWrite(fd -> fdData, recno, trueBase(data)) == UERROR)
return (sfuint) isMuCallErr(BT3WRITE, 0);
在头文件中,trueBase
并BASEOFFSET
定义为以下宏:
/*
* macro for easing the buffer address calculations (who knows what
* may change down the road
*/
#define BASEOFFSET (sizeof(sflong))
#define trueBase(address) ((char *) address - BASEOFFSET)
现在,这就是我想要帮助的内容(我绝不是 C 专家......实际上几乎没有功能)。我需要知道 trueBase 在做什么(或者你最好的猜测)。在我未经训练的眼睛看来,它似乎将指向数据的指针移动了 BASEOFFSET 的长度(在我的系统上是 8 个字节)。
任何了解此特定软件产品的人也可以获得额外的奖励积分!它已经很老了,我真的找不到任何文档。它的评论相当好 - 除了这一点。