libcbor  0.5.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
stack.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017 Pavel Kalvoda <me@pavelkalvoda.com>
3  *
4  * libcbor is free software; you can redistribute it and/or modify
5  * it under the terms of the MIT license. See LICENSE for details.
6  */
7 
8 #include "stack.h"
9 
11 {
12  return (struct _cbor_stack) {.top = NULL, .size = 0};
13 }
14 
15 void _cbor_stack_pop(struct _cbor_stack *stack)
16 {
17  struct _cbor_stack_record *top = stack->top;
18  stack->top = stack->top->lower;
19  _CBOR_FREE(top);
20  stack->size--;
21 }
22 
24 {
25  struct _cbor_stack_record *new_top = _CBOR_MALLOC(sizeof(struct _cbor_stack_record));
26  if (new_top == NULL)
27  return NULL;
28 
29  *new_top = (struct _cbor_stack_record) {stack->top, item, subitems};
30  stack->top = new_top;
31  stack->size++;
32  return new_top;
33 }
size_t size
Definition: stack.h:27
size_t subitems
Definition: stack.h:21
Stack handle - contents and size.
Definition: stack.h:25
struct _cbor_stack_record * lower
Definition: stack.h:19
struct _cbor_stack _cbor_stack_init()
Definition: stack.c:10
Simple stack record for the parser.
Definition: stack.h:18
#define _CBOR_FREE
Definition: common.h:86
#define _CBOR_MALLOC
Definition: common.h:84
void _cbor_stack_pop(struct _cbor_stack *stack)
Definition: stack.c:15
struct _cbor_stack_record * _cbor_stack_push(struct _cbor_stack *stack, cbor_item_t *item, size_t subitems)
Definition: stack.c:23
cbor_item_t * item
Definition: stack.h:20
The item handle.
Definition: data.h:149
struct _cbor_stack_record * top
Definition: stack.h:26