예제 #1
0
파일: cdb.c 프로젝트: alepharchives/ULib
int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos)
{
  if (c->map) {
	 if ((pos > c->size) || (c->size - pos < len)) goto FORMAT;
	 byte_copy(buf,len,c->map + pos);
  }
  else {
	 if (seek_set(c->fd,pos) == -1) return -1;
	 while (len > 0) {
		int r;
		do
		  r = read(c->fd,buf,len);
		while ((r == -1) && (errno == error_intr));
		if (r == -1) return -1;
		if (r == 0) goto FORMAT;
		buf += r;
		len -= r;
	 }
  }
  return 0;

  FORMAT:
  errno = error_proto;
  return -1;
}
예제 #2
0
파일: cdb_read.c 프로젝트: fvigotti/skalibs
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 ;
}
예제 #3
0
파일: cdb.c 프로젝트: BatchDrake/radare2
int cdb_findnext(struct cdb *c, ut32 u, const char *key, unsigned int len) {
	char buf[8];
	ut32 pos;
	int m;

	if (!c->loop) {
		if (!cdb_read (c, buf, 8, (u << 3) & 2047))
			return -1;
		ut32_unpack (buf + 4, &c->hslots);
		if (!c->hslots) {
			return 0;
		}
		ut32_unpack (buf, &c->hpos);
		c->khash = u;
		u >>= 8;
		u %= c->hslots;
		u <<= 3;
		c->kpos = c->hpos + u;
	}

	while (c->loop < c->hslots) {
		if (!cdb_read (c, buf, 8, c->kpos))
			return 0;
		ut32_unpack (buf + 4, &pos);
		if (!pos) return 0;
		c->loop++;
		c->kpos += 8;
		if (c->kpos == c->hpos + (c->hslots << 3))
			c->kpos = c->hpos;
		ut32_unpack (buf, &u);
		if (u == c->khash) {
			if (!seek_set (c->fd, pos))
				return -1;
			if (!getkvlen (c->fd, &u, &c->dlen))
				return -1;
			if (u == 0)
				return -1;
			if (u == len) {
				if ((m = match (c, key, len, pos + KVLSZ))==-1)
					return 0;
				if (m == 1) {
					c->dpos = pos + KVLSZ + len;
					return 1;
				}
			}
		}
	}
	return 0;
}
예제 #4
0
파일: cdb.c 프로젝트: BatchDrake/radare2
int cdb_read(struct cdb *c, char *buf, ut32 len, ut32 pos) {
	if (c->map) {
		if ((pos > c->size) || (c->size - pos < len))
			return 0;
		byte_copy (buf, len, c->map + pos);
		return 1;
	}
	if (!seek_set (c->fd, pos))
		return 0;
	while (len > 0) {
		ssize_t r = read (c->fd, buf, len);
		if (r < 0) return 0;
		buf += r;
		len -= r;
	}
	return 1;
}