Beispiel #1
0
int cfg_blob_copy( blob_t *from, void *to ) {
	size_t len = from->options & BLOB_LENGTH_MASK;
	
	if( to != NULL ) {
		if( is_host_endian( from ) ||
			( ( from->options & BLOB_LENGTH_MASK ) == 1 )
		)
			__copy( from, to );
		else {
			__copy( from, to );
			if( from->options & BLOB_ARRAY )
				switch( len ) {
					case 2:
						for( char *limit = to + 2 * from->array.length, *cyc = to;
							cyc < limit;
							cyc += 2
						)
							bswap_16( *( ( uint16_t* ) cyc ) );
						break;
					case 4:
						for( char *limit = to + 4 * from->array.length, *cyc = to;
							cyc < limit;
							cyc += 4
						)
							bswap_32( *( ( uint32_t* ) cyc ) );
						break;
					default:
						for( char *limit = to + len * from->array.length, *cyc = to;
							cyc < limit;
							cyc += len
						)
							__swap_bytes( cyc, len );
				}
			else
				switch( len ) {
					case 2:
						bswap_16( *( ( uint16_t* ) to ) );
						break;
					case 4:
						bswap_32( *( ( uint32_t* ) to ) );
						break;
					default:
						__swap_bytes( to, len );
				};
		}
	}

	if( from->options & BLOB_ARRAY )
		return ( len * from->array.length )
	else
		return len;
}
Beispiel #2
0
deque::deque(deque const &other) {
    sz = other.size();;
    __size = sz;
    __copy(other);
    head = a;
    tail = a + sz;
}
Beispiel #3
0
static void copy_len(int idx, int len, array_t des, array_t src)
{
        __list(src);
        __list(des);
        __list_idx(idx, des);
        __list_space_len(idx, len, des);
        __copy(des->priv->array, src->priv->array, idx, len);
}
Beispiel #4
0
static void copy(array_t des, array_t src)
{
        __list(src);
        __list(des);
        __list_space(des, src);
	
	__copy(des->priv->array, src->priv->array, 0, src->priv->count);
        des->priv->count += src->priv->count;
}
Beispiel #5
0
static void copy_idx(int idx, array_t des, array_t src)
{
        __list(src);
        __list(des);
        __list_idx(idx, des);
        __list_space_idx(idx, des, src);
	
	__copy(des->priv->array, src->priv->array, idx, src->priv->count);
        des->priv->count += src->priv->count;
}
int __backport_genl_register_family(struct genl_family *family)
{
	int i, ret;

#define __copy(_field) family->family._field = family->_field
	__copy(id);
	__copy(hdrsize);
	__copy(version);
	__copy(maxattr);
	strncpy(family->family.name, family->name, sizeof(family->family.name));
	__copy(netnsok);
	__copy(pre_doit);
	__copy(post_doit);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
	__copy(parallel_ops);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
	__copy(module);
#endif
#undef __copy

	ret = genl_register_family(&family->family);
	if (ret < 0)
		return ret;

	family->attrbuf = family->family.attrbuf;
	family->id = family->family.id;

	for (i = 0; i < family->n_ops; i++) {
		ret = genl_register_ops(&family->family, &family->ops[i]);
		if (ret < 0)
			goto error;
	}

	for (i = 0; i < family->n_mcgrps; i++) {
		ret = genl_register_mc_group(&family->family,
					     &family->mcgrps[i]);
		if (ret)
			goto error;
	}

	return 0;

 error:
	backport_genl_unregister_family(family);
	return ret;
}
Beispiel #7
0
void bootmgr_import_boot(char *path)
{
    DIR *d = opendir(path);
    if(d == NULL)
        return;
    struct dirent *dp;
    char to[100];
    char from[100];

    // copy init binary
    INFO("Copy init binary to ramdisk");
    sprintf(from, "%s/init", path);
    __copy(from, "/main_init");
    chmod("/main_init", 0750);

    // /default.prop
    sprintf(from, "%s/default.prop", path);
    __copy(from, "/default.prop");

    // /sbin/adbd
    sprintf(from, "%s/adbd", path);
    __copy(from, "/sbin/adbd");

    while(dp = readdir(d))
    {
        if(strstr(dp->d_name, ".rc") == NULL)
            continue;

        // copy to our ramdisk
        INFO("Copy %s to ramdisk", dp->d_name);
        sprintf(from, "%s/%s", path, dp->d_name);
        sprintf(to, "/%s", dp->d_name);
        __copy(from, to);
        chmod(to, 0750);
    }
    closedir(d);
}
Beispiel #8
0
static struct val *__alloc(enum val_type type, const char *s, size_t len,
			   bool heapalloc, bool mustdup)
{
	struct val *val;
	bool copy;

	ASSERT((type == VT_STR) || (type == VT_SYM));

	/* sanity check */
	if (mustdup)
		ASSERT(!heapalloc);

	/* determine the real length of the string */
	len = s ? strnlen(s, len) : 0;

	/* check preallocated strings */
	val = __get_preallocated(type, s, len);
	if (val)
		goto out;

	/* can we inline it? */
	copy = __inlinable(len);

	/* we'll be storing a pointer - strdup as necessary */
	if (!copy && mustdup) {
		char *tmp;

		tmp = malloc(len + 1);
		if (!tmp) {
			val = ERR_PTR(-ENOMEM);
			goto out;
		}

		__copy(tmp, s, len);

		/* we're now using the heap */
		heapalloc = true;
		s = tmp;
	}

	val = __val_alloc(type);
	if (IS_ERR(val))
		goto out;

	val->static_alloc = copy || !heapalloc;
	val->inline_alloc = copy;
	set_len(val, len);

	if (copy) {
		__copy(val->_set_str_inline, s, len);

		if (heapalloc)
			free((char *) s);
	} else {
		val->_set_str_ptr = s;
	}

	return val;

out:
	if (heapalloc)
		free((char *) s);

	return val;
}
Beispiel #9
0
vector::vector(vector const &other) {
    sz = other.size();
    __size = sz;
    __copy(other);
}