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

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

From: ronnie sahlberg <ronniesahlberg@xxxxxxxxx>
Date: Fri, 22 Jul 2005 17:30:04 -0400
Sure,   

We also need equivalent functions for allocations with capture file
scope/lifetime to get rid of all the gmemchunks and friends  but where
should we put the free all function?



On 7/22/05, LEGO <luis.ontanon@xxxxxxxxx> wrote:
> 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;
> }
> 
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev
>