Ethereal-dev: [Ethereal-dev] Re: [Ethereal-cvs] rev 14984: /trunk/epan/: Makefile.common emem.

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

Date: Fri, 22 Jul 2005 13:04:29 +0200
On 7/22/05, sahlberg@xxxxxxxxxxxx <sahlberg@xxxxxxxxxxxx> wrote:
>  EMEM : a simple and FAST api to allocate memory that will be automatically freed() when the next packet is dissected.

If no one has something against I'll check in these three bellow this eve:

gchar* ep_strdup(gchar* src) {
	guint len = strlen(src);
	
	return strncpy(ep_alloc(len), src, len);
}

guint8* ep_memdup(guint8* src, size_t len) {
	return memcpy(ep_alloc(len), src, len);
}

gchar* ep_strdup_printf(const gchar* fmt, ...)
{
	va_list ap;
	guint len;
	gchar* dst;

	va_start(ap,fmt);
	len = g_printf_string_upper_bound (fmt, ap);
	
	if ( len < (EMEM_PACKET_CHUNK_SIZE>>2) ) {
		dst = ep_alloc(len);
		g_vsnprintf (dst, len, fmt, ap);
	} else {
		len = EMEM_PACKET_CHUNK_SIZE>>2 - 4;

		dst = ep_alloc(len);
		g_vsnprintf (dst, len, fmt, ap);
		memcpy(dst+len,"...",4);
	}
	
	va_end(ap);
	return dst;
}