Esempio n. 1
0
/*----------------------------------------------------------------------*/
KpInt32_t Kp_skip (
			KpFd_t		FAR *fd,
			KpInt32_t	nbytes)
{

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

	switch (fd->type) {
	/* if regular file, error */
	case KCMS_IO_SYSFILE: 
		return KCMS_IO_ERROR;

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

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

	default:
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
Esempio n. 2
0
/*----------------------------------------------------------------------*/
KpInt32_t Kp_set_position (
			KpFd_t		FAR *fd,
			KpInt32_t	nOffset)
{

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

	switch (fd->type) {
	/* if regular file, error */
	case KCMS_IO_SYSFILE: 
		return KCMS_IO_ERROR;

	/* if memory file, move pointer */
	case KCMS_IO_MEMFILE:
		if (nOffset >= fd->fd.mem.size)
			return KCMS_IO_ERROR;

		fd->fd.mem.pos = nOffset;
		break;

	default:
		return KCMS_IO_ERROR;
	}

	return KCMS_IO_SUCCESS;
}
Esempio n. 3
0
/*----------------------------------------------------------------------*/
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;
}
Esempio n. 4
0
/*----------------------------------------------------------------------*/
KpInt32_t Kp_get_crc (
			KpFd_t		FAR *fd,
			KpCrc32_t	FAR *crc)
{
	if (KpFdCheck (fd) != KCMS_IO_SUCCESS)
		return KCMS_IO_ERROR;

	if (fd->type != KCMS_IO_CALCCRC)
		return KCMS_IO_ERROR;

	*crc = fd->fd.crc32;
	return KCMS_IO_SUCCESS;
}
Esempio n. 5
0
/*----------------------------------------------------------------------*/
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;
}
Esempio n. 6
0
/*----------------------------------------------------------------------*/
KpInt32_t Kp_close (
			KpFd_t	FAR *fd)
{
	KpInt32_t		Status;

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

	Status = KCMS_IO_SUCCESS;
	switch (fd->type) {
	case KCMS_IO_NULLFILE:
		break;

	case KCMS_IO_SYSFILE:
		if (1 != KpFileClose (fd->fd.sys))
			Status = KCMS_IO_ERROR;

		break;

	case KCMS_IO_MEMFILE:
		/* force a bus error if fd is used after it's freed */
		fd->fd.mem.buf = (char FAR *) -1L;
		fd->fd.mem.size = 0;
		fd->fd.mem.pos = 0;	/* set offset to point to start of buffer */
		break;
		
#if !defined KCMS_NO_CRC
	case KCMS_IO_CALCCRC:
		fd->fd.crc32 = 0;
		break;
#endif

	default:
		Status = KCMS_IO_ERROR;
		break;
	}

	fd->type = KCMS_IO_NULLFILE;
	return Status;
}