src/libs/elektra/opmphm_vstack.c
/**
 * Pushes an element in the Vstack and resizes the stack if needed.
 *
 * @ingroup vstack
 * @param data the element
 * @retval 1 on error
 * @retval 0 otherwise
 */
Pushes an element in the Vstack and resizes the stack if needed.
@ingroup vstack
@param data the element
@retval 1 on error
@retval 0 otherwise
Pushes an element in the Vstack and resizes the stack if needed . @ingroup vstack @param data the element @retval 1 on error @retval 0 otherwise
int elektraVstackPush (Vstack * stack, void * data)
{
	if (!stack) return 1;
	if ((size_t) (stack->head - stack->data) >= stack->size)
	{
		stack->size <<= 1;
		ELEKTRA_LOG_DEBUG ("VSTACK REALLOC TO = %zu", stack->size);
		int diff = stack->head - stack->data;
		if (elektraRealloc ((void **)&stack->data, stack->size * sizeof (void *)) == -1)
		{
			stack->size >>= 1;
			return 1;
		}
		stack->head = stack->data + diff;
	}
	*stack->head = data;
	++stack->head;
	return 0;
}
int elektraVstackPush ( Vstack * stack , void * data ) { if ( ! stack ) return 1 ; if ( ( size_t ) ( stack -> head - stack -> data ) >= stack -> size ) { stack -> size <<= 1 ; ELEKTRA_LOG_DEBUG ( " " , stack -> size ) ; int diff = stack -> head - stack -> data ; if ( elektraRealloc ( ( void * * ) & stack -> data , stack -> size * sizeof ( void * ) ) == -1 ) { stack -> size >>= 1 ; return 1 ; } stack -> head = stack -> data + diff ; } * stack -> head = data ; ++ stack -> head ; return 0 ; }
Pushes an element in the Vstack and resizes the stack if needed.
Pushes an element in the Vstack and resizes the stack if needed .
// grow // save head // restore head