Exemple #1
0
/* fut_copy_gtbl makes an exact copy of an existing fut_gtbl_t
 */
fut_gtbl_p
	fut_copy_gtbl (fut_gtbl_p gtbl)
{
fut_gtbl_p		new_gtbl;
KpInt32_t		gsize;
KpHandle_t		h;

				/* check for valid gtbl */
	if ( ! IS_GTBL(gtbl) ) {
		return (FUT_NULL_GTBL);
	}

	new_gtbl = fut_alloc_gtbl ();	/* allocate the new gtbl structure */
	if ( new_gtbl == FUT_NULL_GTBL ) {
		DIAG("fut_copy_gtbl: can't alloc grid table struct.\n", 0);
		return (FUT_NULL_GTBL);
	}

	h = new_gtbl->handle;	/* save handle before copying over old gtbl */

	*new_gtbl = *gtbl;		/* copy entire struct except reference count */

	new_gtbl->handle = h;
	new_gtbl->ref = 0;		/* first reference */

	if (gtbl->tbl != NULL) {	/* copy fixed gtbl data */
		gsize = gtbl->tbl_size / (KpInt32_t)sizeof(fut_gtbldat_t);
		new_gtbl->tbl = fut_alloc_gtbldat (new_gtbl);
		if ( new_gtbl->tbl == NULL ) {
			DIAG("fut_copy_gtbl: can't alloc grid table array.\n", 0);
			goto ErrOut;
		}
		new_gtbl->tblHandle = getHandleFromPtr((KpGenericPtr_t)new_gtbl->tbl);

		/* copy the table entries */
		KpMemCpy (new_gtbl->tbl, gtbl->tbl, gtbl->tbl_size);
	}

	if (gtbl->refTbl != NULL) {	/* copy reference gtbl data */
		new_gtbl->refTbl = fut_alloc_gmftdat (new_gtbl);
		if (new_gtbl->refTbl == NULL ) {
			DIAG("fut_copy_gtbl: can't alloc ref grid table array.\n", 0);
			goto ErrOut;
		}

		/* copy the table entries */
		KpMemCpy (new_gtbl->refTbl, gtbl->refTbl, gtbl->tbl_size);
	}

	return (new_gtbl);
	

ErrOut:
	fut_free_gtbl (new_gtbl);
	return (FUT_NULL_GTBL);
}
Exemple #2
0
/* fut_copy_otbl makes an exact copy of an existing fut_otbl_t
 */
fut_otbl_p
	fut_copy_otbl (fut_otbl_p otbl)
{
fut_otbl_p		new_otbl;
KpHandle_t		h;

	/* check for valid otbl */
	if ( ! IS_OTBL(otbl) ) {
		return (FUT_NULL_OTBL);
	}

	/* allocate the new otbl structure */
	new_otbl = fut_alloc_otbl ();
	if ( new_otbl == FUT_NULL_OTBL ) {
		DIAG("fut_copy_otbl: can't alloc output table struct.\n", 0);
		return (FUT_NULL_OTBL);
	}

	h = new_otbl->handle;	/* save handle before copying over old otbl */

	*new_otbl = *otbl;		/* copy entire struct except reference count */

	new_otbl->handle = h;
	new_otbl->ref = 0;		/* first reference */

	if (otbl->tbl != NULL) {	/* copy fixed otbl data */
		new_otbl->tbl = fut_alloc_otbldat (new_otbl);
		if ( new_otbl->tbl == NULL ) {
			DIAG("fut_copy_otbl: can't alloc output table array.\n", 0);
			goto ErrOut;
		}
		new_otbl->tblHandle = getHandleFromPtr((KpGenericPtr_t)new_otbl->tbl);

		/* copy the table entries */
		KpMemCpy (new_otbl->tbl, otbl->tbl, FUT_OUTTBL_ENT * sizeof (fut_otbldat_t));
	}

	if (otbl->refTbl != NULL) {	/* copy reference otbl data */
		new_otbl->refTbl = fut_alloc_omftdat (new_otbl, new_otbl->refTblEntries);
		if (new_otbl->refTbl == NULL ) {
			DIAG("fut_copy_otbl: can't alloc output table array.\n", 0);
			goto ErrOut;
		}

		/* copy the table entries */
		KpMemCpy (new_otbl->refTbl, otbl->refTbl, new_otbl->refTblEntries * sizeof (mf2_tbldat_t));
	}

	return (new_otbl);
	

ErrOut:
	fut_free_otbl (new_otbl);
	return (FUT_NULL_OTBL);
}
/*----------------------------------------------------------------------*/
KpInt32_t Kp_write (
			KpFd_t			FAR *fd,
			KpLargeBuffer_t	buf,
			KpInt32_t		nbytes)
{
	void KPHUGE *memPtr;

	if (KpFdCheck (fd) != KCMS_IO_SUCCESS)
		return KCMS_IO_ERROR;

	/* validate destination */
	if (buf == NULL)
		return KCMS_IO_ERROR;

	switch (fd->type) {

	/* regular file, write it */
	case KCMS_IO_SYSFILE:
		if (1 != KpFileWrite (fd->fd.sys, buf, nbytes))
			return KCMS_IO_ERROR;

		break;

	/* memory file, copy to memory */
	case KCMS_IO_MEMFILE:
		if (fd->fd.mem.pos + nbytes > fd->fd.mem.size)
			return KCMS_IO_ERROR;

		/* validate destination */
		if (fd->fd.mem.buf == NULL)
			return KCMS_IO_ERROR;

		memPtr = (char KPHUGE *) fd->fd.mem.buf + fd->fd.mem.pos;

		KpMemCpy (memPtr, buf, nbytes);

		fd->fd.mem.pos += nbytes;
		break;

#if !defined KCMS_NO_CRC
	/* calculate CRC */
	case KCMS_IO_CALCCRC:
		fd->fd.crc32 = Kp_Crc32 (fd->fd.crc32, nbytes, (KpChar_p) buf);
		break;
#endif

	default:
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
/*----------------------------------------------------------------------*/
KpInt32_t Kp_read (
			KpFd_t			FAR *fd,
			KpLargeBuffer_t	buf,
			KpInt32_t		nbytes)
{
	void KPHUGE *memPtr;

	if (KpFdCheck (fd) != KCMS_IO_SUCCESS)
		return KCMS_IO_ERROR;

	/* validate source */
	if (buf == NULL)
		return KCMS_IO_ERROR;


	switch (fd->type) {

	/* if regular file, read it */
	case KCMS_IO_SYSFILE: 
		if (1 != KpFileRead (fd->fd.sys, buf, &nbytes))
			return KCMS_IO_ERROR;

		break;

	/* if memory file, copy from memory */
	case KCMS_IO_MEMFILE:
		/* check for attemptting to read too much */
		if (fd->fd.mem.pos + nbytes > fd->fd.mem.size)
			return KCMS_IO_ERROR;

		/* validate source? */
		if (fd->fd.mem.buf == NULL)
			return KCMS_IO_ERROR;

		memPtr = (char KPHUGE *) fd->fd.mem.buf + fd->fd.mem.pos;

		KpMemCpy (buf, memPtr, nbytes);

		fd->fd.mem.pos += nbytes;
		break;

	default:
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
Exemple #5
0
/* fut_copy copies an existing fut.
 */
fut_p
	fut_copy (fut_p fut)
{
fut_p		new_fut;
KpInt32_t	i;
KpHandle_t	h;

	if ( ! IS_FUT(fut)) {
		return (0);
	}

				/* allocate basic fut_structure */
	new_fut = fut_alloc_fut ();
	if ( new_fut == FUT_NULL ) {
		return (FUT_NULL);
	}

				/* save handle before copying over old fut */
	h = new_fut->handle;

				/* copy over all data (including pointers */
	*new_fut = *fut;

				/* now copy back handle */
	new_fut->handle = h;

				/* copy id string */
	new_fut->idstr = 0;
/*	(void) fut_set_idstr (new_fut, fut->idstr); */

				/* copy input tables */
	for ( i=0; i<FUT_NICHAN; i++ ) {
		new_fut->itbl[i] = (IS_SHARED (fut->itbl[i])) ?
							fut_share_itbl (fut->itbl[i]) : fut_copy_itbl (fut->itbl[i]);
		new_fut->itblHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->itbl[i]);
	}

				/* copy output channels */
	for ( i=0; i<FUT_NOCHAN; i++ ) {
		new_fut->chan[i] = fut_copy_chan (fut->chan[i]);
		new_fut->chanHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->chan[i]);
	}

				/* now check that all copies were succesful */
	if ( new_fut->idstr == 0 && fut->idstr != 0 ) {
		goto ErrOut;
	}

	for ( i=0; i<FUT_NICHAN; i++ ) {
		if ( new_fut->itbl[i] == 0 && fut->itbl[i] != 0) {
			goto ErrOut;
		}
	}
	for ( i=0; i<FUT_NOCHAN; i++ ) {
		if ( new_fut->chan[i] == 0 && fut->chan[i] != 0) {
			goto ErrOut;
		}
	}

	for ( i=0; i<FUT_NMCHAN; i++ ) {	/* free extra reference tables */
		if (NULL != fut->mabInRefTblHandles[i])
		{
			new_fut->mabInTblEntries[i] = fut->mabInTblEntries[i];
			new_fut->mabInRefTbl[i] = (mf2_tbldat_p)
									allocBufferPtr (new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t));
			KpMemCpy (new_fut->mabInRefTbl[i], fut->mabInRefTbl[i],
													new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t));
			new_fut->mabInRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabInRefTbl[i]);
		}

		if (NULL != fut->mabOutRefTblHandles[i])
		{
			new_fut->mabOutTblEntries[i] = fut->mabOutTblEntries[i];
			new_fut->mabOutRefTbl[i] = (mf2_tbldat_p)
									allocBufferPtr (new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t));
			KpMemCpy (new_fut->mabOutRefTbl[i], fut->mabOutRefTbl[i],
													new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t));
			new_fut->mabOutRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabOutRefTbl[i]);
		}
	}

	return (new_fut);
	

ErrOut:
	fut_free (new_fut);
	return (FUT_NULL);
}