Ejemplo n.º 1
0
DEF_TEST(document_dct_encoder, r) {
    REQUIRE_PDF_DOCUMENT(document_dct_encoder, r);
    SkBitmap bm;
    if (GetResourceAsBitmap("mandrill_64.png", &bm)) {
        // Lossy encoding works better on photographs.
        REPORTER_ASSERT(r, count_bytes(bm, true) < count_bytes(bm, false));
    }
}
void Annotations::collect_statistics(KlassSizeStats *sz) const {
  sz->_annotations_bytes = sz->count(this);
  sz->_class_annotations_bytes = sz->count(class_annotations());
  sz->_class_type_annotations_bytes = sz->count(class_type_annotations());
  sz->_fields_annotations_bytes = count_bytes(fields_annotations());
  sz->_fields_type_annotations_bytes = count_bytes(fields_type_annotations());

  sz->_annotations_bytes +=
      sz->_class_annotations_bytes +
      sz->_class_type_annotations_bytes +
      sz->_fields_annotations_bytes +
      sz->_fields_type_annotations_bytes;

  sz->_ro_bytes += sz->_annotations_bytes;
}
Ejemplo n.º 3
0
static void print_root(struct extent_buffer *leaf, int slot)
{
	struct btrfs_root_item *ri;
	struct btrfs_root_item root_item;
	int len;
	char uuid_str[128];

	ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
	len = btrfs_item_size_nr(leaf, slot);

	memset(&root_item, 0, sizeof(root_item));
	read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);

	printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
		(unsigned long long)btrfs_root_bytenr(&root_item),
		btrfs_root_level(&root_item),
		(unsigned long long)btrfs_root_dirid(&root_item),
		btrfs_root_refs(&root_item),
		(unsigned long long)btrfs_root_generation(&root_item));

	if (root_item.generation == root_item.generation_v2) {
		uuid_unparse(root_item.uuid, uuid_str);
		printf("\t\tuuid %s\n", uuid_str);
		if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
			uuid_unparse(root_item.parent_uuid, uuid_str);
			printf("\t\tparent_uuid %s\n", uuid_str);
		}
		if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
			uuid_unparse(root_item.received_uuid, uuid_str);
			printf("\t\treceived_uuid %s\n", uuid_str);
		}
		if (root_item.ctransid) {
			printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
				btrfs_root_ctransid(&root_item),
				btrfs_root_otransid(&root_item),
				btrfs_root_stransid(&root_item),
				btrfs_root_rtransid(&root_item));
		}
	}
	if (btrfs_root_refs(&root_item) == 0) {
		struct btrfs_key drop_key;
		btrfs_disk_key_to_cpu(&drop_key,
				      &root_item.drop_progress);
		printf("\t\tdrop ");
		btrfs_print_key(&root_item.drop_progress);
		printf(" level %d\n", root_item.drop_level);
	}
}
Ejemplo n.º 4
0
Archivo: rasm.c Proyecto: 111X/radare
int rasm_disasm(const char *arch, ut64 *offset, const char *str, unsigned char *data)
{
	char buf[4096];
	int sz;
	/* TODO: Use internal disasembler */
	/* TODO: parse hexpairs and disassemble */
	//sz = strlen(str)/2;
	sz = count_bytes(str);
	snprintf(buf, 4095, "echo 'wx %s && pd' | radare -e asm.arch=%s -e asm.syntax=0 -e asm.bytes=0 -e asm.offset=0 -e asm.flags=0 -e asm.lines=0 -nvw malloc://%d", str, arch, sz);
	system(buf);
	return 0;
}
Ejemplo n.º 5
0
/*
 * Do a strncpy, return length of string without final '\0'.
 * 'count' is the user-supplied count (return 'count' if we
 * hit it), 'max' is the address space maximum (and we return
 * -EFAULT if we hit it).
 */
static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
{
	long res = 0;

	/*
	 * Truncate 'max' to the user-specified limit, so that
	 * we only have one limit we need to check in the loop
	 */
	if (max > count)
		max = count;

	while (max >= sizeof(unsigned long)) {
		unsigned long c;

		/* Fall back to byte-at-a-time if we get a page fault */
		if (unlikely(__get_user(c,(unsigned long __user *)(src+res))))
			break;
		/* This can write a few bytes past the NUL character, but that's ok */
		*(unsigned long *)(dst+res) = c;
		c = has_zero(c);
		if (c)
			return res + count_bytes(c);
		res += sizeof(unsigned long);
		max -= sizeof(unsigned long);
	}

	while (max) {
		char c;

		if (unlikely(__get_user(c,src+res)))
			return -EFAULT;
		dst[res] = c;
		if (!c)
			return res;
		res++;
		max--;
	}

	/*
	 * Uhhuh. We hit 'max'. But was that the user-specified maximum
	 * too? If so, that's ok - we got as much as the user asked for.
	 */
	if (res >= count)
		return res;

	/*
	 * Nope: we hit the address space limit, and we still had more
	 * characters the caller would have wanted. That's an EFAULT.
	 */
	return -EFAULT;
}
Ejemplo n.º 6
0
static void put_data(int fd, char *null_buf, const CELL * cell,
		     int row, int n, int zeros_r_nulls)
{
    struct fileinfo *fcb = &R__.fileinfo[fd];
    int compressed = fcb->cellhd.compressed;
    int len = compressed ? sizeof(CELL) : fcb->nbytes;
    unsigned char *work_buf, *wk;
    ssize_t nwrite;

    if (row < 0 || row >= fcb->cellhd.rows)
	return;

    if (n <= 0)
	return;

    work_buf = G__alloca(fcb->cellhd.cols * sizeof(CELL) + 1);
    wk = work_buf;

    if (compressed)
	set_file_pointer(fd, row);

    if (compressed)
	wk++;

    convert_int(wk, null_buf, cell, n, len, zeros_r_nulls);

    if (compressed) {
	unsigned char *wk = work_buf + 1;
	int nbytes = count_bytes(wk, n, len);
	unsigned char *compressed_buf;
	int total;

	if (fcb->nbytes < nbytes)
	    fcb->nbytes = nbytes;

	/* first trim away zero high bytes */
	if (nbytes < len)
	    trim_bytes(wk, n, len, len - nbytes);

	total = nbytes * n;
	compressed_buf = G__alloca(total + 1);

	compressed_buf[0] = work_buf[0] = nbytes;

	/* then compress the data */
	nwrite = compressed == 1
	    ? rle_compress(compressed_buf + 1, work_buf + 1, n, nbytes)
	    : zlib_compress(compressed_buf + 1, work_buf + 1, n, nbytes);

	if (nwrite > 0) {
	    nwrite++;

	    if (write(fd, compressed_buf, nwrite) != nwrite)
		G_fatal_error(_("Error writing compressed data for row %d of <%s>"),
			      row, fcb->name);
	}
	else {
	    nwrite = nbytes * n + 1;
	    if (write(fd, work_buf, nwrite) != nwrite)
		G_fatal_error(_("Error writing compressed data for row %d of <%s>"),
			      row, fcb->name);
	}

	G__freea(compressed_buf);
    }
    else {
	nwrite = fcb->nbytes * n;

	if (write(fd, work_buf, nwrite) != nwrite)
	    G_fatal_error(_("Error writing uncompressed data for row %d of <%s>"),
			  row, fcb->name);
    }

    G__freea(work_buf);
}
Ejemplo n.º 7
0
int main(int argc, char** argv){
	int from_date = 0, to_date = INT_MAX, last_cache_time, last_log_time;
	struct stat filestat;
	char* const short_options = "hf:t:u";
	struct option long_options[] = {
		{ "help",	0,	NULL,	'h'},
		{ "from",	1,	NULL,	'f'},
		{ "to",		1,	NULL,	't'},
		{ "update",	0,	NULL,	'u'},
		{ NULL,		0,	NULL,	0  }
	};
	int next_option;
	do{
		next_option = getopt_long(argc, argv, short_options, long_options, NULL);
		switch(next_option){
			case 'h': help(argv[0]);
			break;
			case 'f': from_date = get_date((char*)optarg);
			break;
			case 't': to_date = get_date((char*)optarg);
			break;
			case 'u': makecache(UPDATE); exit(0);
			break;
		}
	}while(next_option != -1);
	if(stat(CACHE_FILE, &filestat) != 0) makecache(NEW);
	else if(filestat.st_size == 0) makecache(NEW);
	int cache = open(CACHE_FILE, O_RDONLY);
	size_t bytes_read;
	unsigned char find_from = 1;
	long from_offset = 0, to_offset = 0;
	bytes_read = read(cache, &s_cache, sizeof(s_cache));
	while(bytes_read == sizeof(s_cache)){
#ifdef DEBUG
			printf("\nfrom=%d\n",s_cache.offset);
#endif
		if( (last_cache_time = s_cache.time) >= from_date && find_from){
			find_from = 0;
			from_offset = s_cache.offset;
		}
		else if(s_cache.time >= to_date)
			to_offset = s_cache.offset;
		bytes_read = read(cache, &s_cache, sizeof(s_cache));
	}
	close(cache);
	if(find_from){
		printf("\nНачальная дата поиска старше последней записи логов\n");
		exit(11);
	}
	if(to_offset == 0){
		stat(LOG_FILE, &filestat);
		to_offset = filestat.st_size;
	}
	if(to_offset <= from_offset){
		printf("\nНеверно выбраны начало и конец диапазона дат,\n"
			"\tлибо сведения за указанный период отсутствуют\n");
			exit(12);
	}
	printf("\nПровожу подсчет (от %d до %d)\n", from_offset, to_offset);
	printf("\n====================================================================\n");
	last_log_time = count_bytes(from_offset, to_offset, from_date, to_date);
	printf("\n====================================================================\n");
	if(last_log_time - last_cache_time > TIME_INTERVAL){
		printf("\nЗаписи файла кеша устарели. Обновляю...\n");
		makecache(UPDATE);
//		count_bytes(from_offset, to_offset, from_date, to_date);
	}
	exit(0);
}