コード例 #1
0
ファイル: module.c プロジェクト: mingpen/OpenNT
LOCAL void ReadNB05(void)
{
	ulong		cnt;
	ushort		tMod = 0;
	ulong		i;

	// locate directory, read number of entries, allocate space, read
	// directory entries and sort into ascending module index order

	if ((link_read (exefile, (char *)&lfoDir, sizeof (long)) != sizeof (long)) ||
	  (link_lseek (exefile, lfoDir + lfoBase, SEEK_SET) == -1L) ||
	  (link_read (exefile, (char *)&DirHead, sizeof (DirHead)) !=
	  sizeof (OMFDirHeader))) {
		ErrorExit(ERR_INVALIDEXE, NULL, NULL);
	}

	if (!DirHead.cDir) {
		ErrorExit(ERR_INVALIDEXE, NULL, NULL);
	}

	cSST = DirHead.cDir;

	// read directory into local memory to sort, then copy to far memory buffer

	cnt = (cSST + 6) * sizeof (OMFDirEntry);
	DASSERT(cnt <= UINT_MAX);

	if ((pDir = (OMFDirEntry *)TrapMalloc ((size_t)cnt)) == NULL) {
		ErrorExit(ERR_NOMEM, NULL, NULL);
	}

	if (link_read (exefile, (char *)pDir, (size_t)(sizeof (OMFDirEntry) * cSST)) !=
		 (sizeof (OMFDirEntry) * cSST)) {
		ErrorExit(ERR_INVALIDEXE, NULL, NULL);
	}

	for (i = 0; i < cSST; i++) {
		if ((pDir[i].iMod != 0) && (pDir[i].iMod != 0xffff)) {
			if (pDir[i].iMod != tMod) {
				if (pDir[i].SubSection != sstModule) {
					// module entry not first, need to sort
					break;
				}

				tMod = pDir[i].iMod;
			}
		}
	}

	if (i != cSST) {
		qsort(pDir, (size_t) cSST, sizeof(OMFDirEntry), modsort);
	}

}
コード例 #2
0
ファイル: son_phy.c プロジェクト: StratifyLabs/son
int son_phy_lseek(son_phy_t * phy, int32_t offset, int whence){
	if( phy->message ){
		return phy_lseek_message(phy, offset, whence);
	}
	if( phy->driver == 0 ){
		if( fseek(phy->f, offset, whence) == 0 ){
			return ftell(phy->f);
		}
		return -1;
	} else {
#if defined __link
		return link_lseek(phy->driver, phy->fd, offset, whence);
#else
		return -1;
#endif
	}
}
コード例 #3
0
ファイル: module.c プロジェクト: mingpen/OpenNT
LOCAL void CopyTable(OMFDirEntry *pDir, _vmhnd_t *pAddr, ulong *pSize)
{
	_vmhnd_t TableAddr;
	char	 *pTable;

	if ((TableAddr = (_vmhnd_t)TrapMalloc (pDir->cb)) == NULL) {
		ErrorExit(ERR_NOMEM, NULL, NULL);
	}

	pTable = (char *) TableAddr;

	link_lseek(exefile, pDir->lfo + lfoBase, SEEK_SET);

	if (link_read(exefile, pTable, pDir->cb) != pDir->cb) {
		ErrorExit(ERR_INVALIDEXE, NULL, NULL);
	}

	*pAddr = TableAddr;
	*pSize = pDir->cb;
}