Exemple #1
0
static inline int copyfds (char *s, int const *fds, unsigned int n, unsigned char const *bits)
{
  register unsigned int i = 0 ;
  for (; i < n ; i++)
  {
    int fd = fds[i] ;
    if (fd < 0) return (errno = EINVAL, -1) ;
    if (bitarray_peek(bits, i)) fd = - fd - 1 ;
#ifdef SKALIBS_HASANCILAUTOCLOSE
    else
    {
      fd = dup(fd) ;
      if (fd < 0)
      {
        int e = errno ;
        while (i--)
        {
          s -= sizeof(int) ;
          byte_copy((char *)fd, sizeof(int), s) ;
          if (fd >= 0) fd_close(fd) ;
        }
        errno = e ;
        return 0 ;
      }
    }
#else
#endif
    byte_copy(s, sizeof(int), (char const *)&fd) ;
    s += sizeof(int) ;
  }
  return 1 ;
}
Exemple #2
0
static void s6rc_graph_closure_rec (recinfo_t *recinfo, unsigned int i)
{
  if (!bitarray_peek(recinfo->mark, i))
  {
    unsigned int j = recinfo->db->services[i].ndeps[recinfo->h] ;
    bitarray_set(recinfo->mark, i) ;
    while (j--) s6rc_graph_closure_rec(recinfo, recinfo->db->deps[recinfo->h * recinfo->db->ndeps + recinfo->db->services[i].deps[recinfo->h] + j]) ;
    recinfo->bits[i] |= recinfo->mask ;
  }
}
unsigned int bitarray_firstclear (register unsigned char const *s, unsigned int max)
{
  unsigned int n = bitarray_div8(max) ;
  register unsigned int i = 0 ;
  for (; i < n ; i++) if (s[i] != 0xffU) break ;
  if (i == n) return max ;
  i <<= 3 ;
  while ((i < max) && bitarray_peek(s, i)) i++ ;
  return i ;
}
unsigned int bitarray_firstclear_skip (register unsigned char const *s, unsigned int max, unsigned int skip)
{
  register unsigned int i = bitarray_div8(skip) ;
  register unsigned int j = i << 3 > max ? max : i << 3 ;
  if (i && s[i-1] != 0xffU)
  {
    while ((skip < j) && bitarray_peek(s, skip)) skip++ ;
    if (skip < j) return skip ;
  }
  return j + bitarray_firstclear(s + i, max - j) ;
}