Ejemplo n.º 1
0
unsigned int fd_catn (int from, int to, unsigned int n)
{
  unsigned int w = 0 ;
  if (n >= IOBUFFER_SIZE)
  {
    iobuffer b ;
    if (!iobuffer_init(&b, from, to)) return 0 ;
    while (n >= IOBUFFER_SIZE)
    {
      register int r = iobuffer_fill(&b) ;
      if (r <= 0)
      {
        iobuffer_finish(&b) ;
        if (!r) errno = EPIPE ;
        return w ;
      }
      if (iobuffer_flush(&b) < 0)
      {
        iobuffer_finish(&b) ;
        return w ;
      }
      n -= r ; w += r ;
    }
    iobuffer_finish(&b) ;
  }

  {
    char buf[n] ;
    unsigned int r = allread(from, buf, n) ;
    unsigned int v = 0 ;
    if (r) v = allwrite(to, buf, r) ;
    w += v ;
  }
  return w ;
}
Ejemplo n.º 2
0
int read_addr(int addr)
{
	if (_lseek(fdr_status_CDI, addr, SEEK_SET) < 0) {
		perror("Failed to seek");
		exit(1);
	}

	allread(fdr_status_CDI, &read_value, 4);

	return read_value;
}
Ejemplo n.º 3
0
int read_flag(int flag)
{
	if (_lseek(fdr_status_CDI, flag, SEEK_SET) < 0) {
		perror("Failed to seek");
		exit(1);
	}

	allread(fdr_status_CDI, &read_value, 4);

	return read_value;
}
unsigned int randomegd_readnb (int s, char *x, unsigned int n)
{
  unsigned int w = 0 ;
  while ((n - w) >= 255)
  {
    char c[2] = { 0x01, 0xFF } ;
    register unsigned char wtmp ;
    if (allwrite(s, c, 2) < 2) return w ;
    if (sanitize_read(fd_read(s, c+1, 1)) < 1) return w ;
    wtmp = allread(s, x + w, c[1]) ;
    w += wtmp ;
    if ((wtmp < (unsigned char)c[1]) || ((unsigned char)c[1] < 0xFF)) return w ;
  }
  if (w < n)
  {
    char c[2] = "\001" ;
    c[1] = n - w ;
    if (allwrite(s, c, 2) < 2) return w ;
    if (sanitize_read(fd_read(s, c+1, 1)) < 1) return w ;
    w += allread(s, x + w, c[1]) ;
  }
  return w ;
}
Ejemplo n.º 5
0
int cdb_read (struct cdb *c, char *buf, unsigned int len, uint32 pos)
{
  if (c->map)
  {
    if ((pos > c->size) || (c->size - pos < len)) return (errno = EPROTO, -1) ;
    byte_copy(buf, len, c->map + pos) ;
  }
  else
  {
    if (seek_set(c->fd, pos) < 0) return -1 ;
    if (allread(c->fd, buf, len) < len) return -1 ;
  }
  return 0 ;
}
Ejemplo n.º 6
0
int main (void)
{
  char buf[TAIN_PACK] ;
  tain_t now, adj ;
  localtmn_t l ;
  char fmt[LOCALTMN_FMT] ;
  PROG = "s6-clockview" ;

  if (allread(0, buf, TAIN_PACK) < TAIN_PACK) strerr_diefu1sys(111, "read from stdin") ;
  tain_unpack(buf, &adj) ;
  if (!sysclock_get(&now)) strerr_diefu1sys(111, "sysclock_get") ;
  if (!localtmn_from_sysclock(&l, &now, 1)) strerr_diefu1sys(111, "localtmn_from_sysclock") ;
  if (buffer_puts(buffer_1, "before: ") < 0) goto fail ;
  if (buffer_put(buffer_1, fmt, localtmn_fmt(fmt, &l)) < 0) goto fail ;
  tain_add(&now, &now, &adj) ;
  if (!localtmn_from_sysclock(&l, &now, 1)) strerr_diefu1sys(111, "localtmn_from_sysclock") ;
  if (buffer_puts(buffer_1, "\nafter:  ") < 0) goto fail ;
  if (buffer_put(buffer_1, fmt, localtmn_fmt(fmt, &l)) < 0) goto fail ;
  if (buffer_putflush(buffer_1, "\n", 1) < 0) goto fail ;
  return 0 ;
 fail:
  strerr_diefu1sys(111, "write to stdout") ;
}
int mininetstring_read (int fd, stralloc *sa, uint32 *w)
{
  if (!*w)
  {
    char pack[2] ;
    switch (fd_read(fd, pack, 2))
    {
      case -1 : return -1 ;
      case 0 : return 0 ;
      case 1 : *w = ((uint32)pack[0] << 8) | (1U << 31) ; break ;
      case 2 : *w = ((uint32)pack[0] << 8) | (uint32)pack[1] | (1U << 30) ; break ;
      default : return (errno = EDOM, -1) ;
    }
  }
  if (*w & (1U << 31))
  {
    char c ;
    switch (fd_read(fd, &c, 1))
    {
      case -1 : return -1 ;
      case 0 : return (errno = EPIPE, -1) ;
      case 1 : *w |= (uint32)c | (1U << 30) ; *w &= ~(1U << 31) ; break ;
      default : return (errno = EDOM, -1) ;
    }
  }
  if (*w & (1U << 30))
  {
    if (!stralloc_readyplus(sa, *w & ~(1U << 30))) return -1 ;
    *w &= ~(1U << 30) ;
  }
  {
    register unsigned int r = allread(fd, sa->s + sa->len, *w) ;
    sa->len += r ; *w -= r ;
  }
  return *w ? -1 : 1 ;
}