include/events/common.h
static inline void *caerCopyEventPacket(void *eventPacket) {
	// Handle empty event packets.
	if (eventPacket == NULL) {
		return (NULL);
	}

	// Calculate needed memory for new event packet.
	caerEventPacketHeader header = (caerEventPacketHeader) eventPacket;
	int32_t eventSize = caerEventPacketHeaderGetEventSize(header);
	int32_t eventNumber = caerEventPacketHeaderGetEventNumber(header);
	int32_t eventCapacity = caerEventPacketHeaderGetEventCapacity(header);
	size_t packetMem = CAER_EVENT_PACKET_HEADER_SIZE + (size_t) (eventSize * eventCapacity);
	size_t dataMem = CAER_EVENT_PACKET_HEADER_SIZE + (size_t) (eventSize * eventNumber);

	// Allocate memory for new event packet.
	caerEventPacketHeader eventPacketCopy = (caerEventPacketHeader) malloc(packetMem);
	if (eventPacketCopy == NULL) {
		// Failed to allocate memory.
		return (NULL);
	}

	// Copy the data over.
	memcpy(eventPacketCopy, eventPacket, dataMem);

	return (eventPacketCopy);
}
/**
 * Make a full copy of an event packet (up to eventCapacity).
 *
 * @param eventPacket an event packet to copy.
 *
 * @return a full copy of an event packet.
 */
Make a full copy of an event packet (up to eventCapacity).
@param eventPacket an event packet to copy.

@return a full copy of an event packet.
Make a full copy of an event packet ( up to eventCapacity ) . @param eventPacket an event packet to copy . @return a full copy of an event packet .
static inline void *caerCopyEventPacket(void *eventPacket) {
	if (eventPacket == NULL) {
		return (NULL);
	}
	caerEventPacketHeader header = (caerEventPacketHeader) eventPacket;
	int32_t eventSize = caerEventPacketHeaderGetEventSize(header);
	int32_t eventNumber = caerEventPacketHeaderGetEventNumber(header);
	int32_t eventCapacity = caerEventPacketHeaderGetEventCapacity(header);
	size_t packetMem = CAER_EVENT_PACKET_HEADER_SIZE + (size_t) (eventSize * eventCapacity);
	size_t dataMem = CAER_EVENT_PACKET_HEADER_SIZE + (size_t) (eventSize * eventNumber);
	caerEventPacketHeader eventPacketCopy = (caerEventPacketHeader) malloc(packetMem);
	if (eventPacketCopy == NULL) {
		return (NULL);
	}
	memcpy(eventPacketCopy, eventPacket, dataMem);
	return (eventPacketCopy);
}
static inline void * caerCopyEventPacket ( void * eventPacket ) { if ( eventPacket == NULL ) { return ( NULL ) ; } caerEventPacketHeader header = ( caerEventPacketHeader ) eventPacket ; int32_t eventSize = caerEventPacketHeaderGetEventSize ( header ) ; int32_t eventNumber = caerEventPacketHeaderGetEventNumber ( header ) ; int32_t eventCapacity = caerEventPacketHeaderGetEventCapacity ( header ) ; size_t packetMem = CAER_EVENT_PACKET_HEADER_SIZE + ( size_t ) ( eventSize * eventCapacity ) ; size_t dataMem = CAER_EVENT_PACKET_HEADER_SIZE + ( size_t ) ( eventSize * eventNumber ) ; caerEventPacketHeader eventPacketCopy = ( caerEventPacketHeader ) malloc ( packetMem ) ; if ( eventPacketCopy == NULL ) { return ( NULL ) ; } memcpy ( eventPacketCopy , eventPacket , dataMem ) ; return ( eventPacketCopy ) ; }
Make a full copy of an event packet (up to eventCapacity).
Make a full copy of an event packet ( up to eventCapacity ) .
// Handle empty event packets. // Calculate needed memory for new event packet. // Allocate memory for new event packet. // Failed to allocate memory. // Copy the data over.