Example #1
0
/**
 * list_move_tail - delete from one list and add as another's tail
 * @list: the entry to move
 * @head: the head that will follow our entry
 */
void list_move_tail(struct list_head* list,
                    struct list_head* head)
{
    __check_head(head);
    __list_del(list->prev, list->next);
    list_add_tail(list, head);
}
Example #2
0
ssize_t conf_read_bin(const char *file,
		      const void *key, size_t key_len,
		      void *value, size_t value_len)
{
	int fd;
	ssize_t r = -1;

	if ((fd = open(file, O_RDONLY)) < 0) {
		DBGE("open %s failed", file);
		return -1;
	}

	if (__check_head(fd) < 0)
		goto RTN;

	if (__find_key(fd, -1, key, key_len, value_len) < 0)
		goto RTN;

	if (readn(fd, value, value_len) != value_len)
		goto RTN;

	r = 0;

RTN:
	close(fd);
	return r;
}
Example #3
0
ssize_t conf_op_bin(int type, const char *file,
		       const void *key, size_t key_len,
		       const void *value, size_t value_len)
{
	int fd = -1, fd_new;
	char file_tmp[PATH_MAX];
	ssize_t r = -1;

	if (pathname_tmp(file, file_tmp, PATH_MAX) < 0)
		return -1;

	if ((fd_new = open(file_tmp, O_WRONLY|O_CREAT, ACCESSPERMS)) < 0) {
		DBGE("open %s failed", file_tmp);
		return -1;
	}
	if ((r = __write_head(fd_new)) < 0)
		goto RTN;

	if ((fd = open(file, O_RDONLY)) < 0) {
		if (ENOENT == errno)
			goto NEW_ITEM;

		goto RTN;
	}

	if (__check_head(fd) < 0)
		goto RTN;

	while(!(r = __find_key(fd, fd_new, key, key_len, value_len)))
		__check_copy(fd, -1, value_len); /* discard value here */

	if (r == -2)
		goto RTN;

NEW_ITEM:
	if (CONF_WRITE == type)
		r = __write_item(fd_new, key, key_len, value, value_len);

	/* r = __copy_left(fd, fd_new); */

RTN:
	close(fd_new);
	if (fd >= 0)
		close(fd);
	if (r >= 0)
		r = rename(file_tmp, file);
	if (r < 0)
		unlink(file_tmp);

	return r;
}
Example #4
0
/**
 * list_add_tail - add a new_ entry
 * @new_: new_ entry to be added
 * @head: list head to add it before
 *
 * Insert a new_ entry before the specified head.
 * This is useful for implementing queues.
 */
void list_add_tail(struct list_head* new_, struct list_head* head)
{
    __check_head(head);
    __list_add(new_, head->prev, head);
}
Example #5
0
/**
 * list_add - add a new_ entry
 * @new_: new_ entry to be added
 * @head: list head to add it after
 *
 * Insert a new_ entry after the specified head.
 * This is good for implementing stacks.
 */
void list_add(struct list_head* new_, struct list_head* head)
{
    __check_head(head);
    __list_add(new_, head, head->next);
}