Logo Search packages:      
Sourcecode: sofia-sip version File versions  Download package

size_t memcspn ( const void *  mem,
size_t  memlen,
const void *  reject,
size_t  rejectlen 
)

Search memory for bytes not in a given set.

The memcspn() function calculates the length of the memory area mem which consists entirely of bytes not in reject.

Parameters:
mem pointer to memory area  
memlen size of mem in bytes
reject pointer to table containing bytes to reject
rejectlen size of reject table
Returns:
The memspn() function returns the number of bytes in the memory area which consists entirely of bytes not in reject.
If rejectlen is 0, or reject is NULL, it returns memlen, size of the memory area.

Definition at line 55 of file memcspn.c.

{
  size_t i;

  unsigned char const *m = mem, *r = reject;

  char rejected[UCHAR_MAX + 1];

  if (rejectlen == 0 || reject == 0)
    return memlen;

  if (mem == NULL || memlen == 0)
    return 0;

  memset(rejected, 0, sizeof rejected);

  for (i = 0; i < rejectlen; i++)
    rejected[r[i]] = 1;

  for (i = 0; i < memlen; i++)
    if (rejected[m[i]])
      break;

  return i;
}


Generated by  Doxygen 1.6.0   Back to index