Path: blob/main/contrib/libcbor/src/cbor/internal/stack.c
39566 views
/*1* Copyright (c) 2014-2020 Pavel Kalvoda <[email protected]>2*3* libcbor is free software; you can redistribute it and/or modify4* it under the terms of the MIT license. See LICENSE for details.5*/67#include "stack.h"89struct _cbor_stack _cbor_stack_init(void) {10return (struct _cbor_stack){.top = NULL, .size = 0};11}1213void _cbor_stack_pop(struct _cbor_stack *stack) {14struct _cbor_stack_record *top = stack->top;15stack->top = stack->top->lower;16_cbor_free(top);17stack->size--;18}1920struct _cbor_stack_record *_cbor_stack_push(struct _cbor_stack *stack,21cbor_item_t *item,22size_t subitems) {23if (stack->size == CBOR_MAX_STACK_SIZE) return NULL;24struct _cbor_stack_record *new_top =25_cbor_malloc(sizeof(struct _cbor_stack_record));26if (new_top == NULL) return NULL;2728*new_top = (struct _cbor_stack_record){stack->top, item, subitems};29stack->top = new_top;30stack->size++;31return new_top;32}333435