/usr/include/void_stack.h is in libregfi-dev 1.0.1+svn287-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | /*
* Copyright (C) 2005,2007,2009-2010 Timothy D. Morgan
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id$
*/
/**
*@file
*
* This is a very simple implementation of a stack which stores chunks of
* memory of any type.
*/
#ifndef _VOID_STACK_H
#define _VOID_STACK_H
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <talloc.h>
#include "compat.h"
/** XXX: document this. */
typedef struct _void_stack
{
void** elements;
unsigned short max_size;
unsigned short top;
} void_stack;
/** XXX: document this. */
typedef struct _void_stack_iterator
{
const void_stack* stack;
unsigned short cur;
} void_stack_iterator;
/** Allocates a new void_stack.
*
* @param max_size the maxiumum number of elements
* which may be pushed onto the stack.
*
* @return a pointer to the newly allocated void_stack,
* or NULL if an error occurred.
*/
_EXPORT()
void_stack* void_stack_new(unsigned short max_size);
/** Makes a shallow copy of void_stack.
*
* @param v the stack to make a copy of.
*
* @return a pointer to the duplicate void_stack, or NULL if an error occurred.
*/
_EXPORT()
void_stack* void_stack_copy(const void_stack* v);
/** Makes a shallow copy of void_stack in reverse order.
*
* @param v the stack to make a copy of.
*
* @return a pointer to the duplicate void_stack
* (which will be in reverse order), or NULL if an error occurred.
*/
_EXPORT()
void_stack* void_stack_copy_reverse(const void_stack* v);
/** Frees the memory associated with a void_stack, but not the elements held
* on the stack.
*
* @param stack the stack to be free()d.
*/
_EXPORT()
void void_stack_free(void_stack* stack);
/** Frees the memory associated with a void_stack and the elements referenced
* by the stack.
*
* Do not use this function if the elements of the stack
* are also free()d elsewhere, or contain pointers to other memory which
* cannot be otherwise free()d.
*
* @param stack the stack to be free()d.
*/
_EXPORT()
void void_stack_free_deep(void_stack* stack);
/** Query the current number of elements on a void_stack()
*
* @param stack the void_stack to query
*
* @return the number of elements currently on the stack.
*/
_EXPORT()
unsigned short void_stack_size(const void_stack* stack);
/** Removes the top element on a void_stack and returns a reference to it.
*
* @param stack the void_stack to pop
*
* @return a pointer to the popped stack element, or NULL if no elements exist
* on the stack.
*/
_EXPORT()
void* void_stack_pop(void_stack* stack);
/** Puts a new element on the top of a void_stack.
*
* @param stack the void_stack being modified.
* @param e the element to be added
*
* @return true if the element was successfully added, false otherwise.
*/
_EXPORT()
bool void_stack_push(void_stack* stack, void* e);
/** Returns a pointer to the current element on the top of the stack.
*
* @param stack the void_stack being queried.
*
* @return a pointer to the current element on the top of the stack, or NULL if
* no elements exist in the stack.
*/
_EXPORT()
const void* void_stack_cur(const void_stack* stack);
/** Creates a new iterator for the specified void_stack.
*
* @param stack the void_stack to be referenced by the new iterator
*
* @return a new void_stack_iterator, or NULL if an error occurred.
*/
_EXPORT()
void_stack_iterator* void_stack_iterator_new(const void_stack* stack);
/** Frees a void_stack_iterator.
*
* Does not affect the void_stack referenced by the iterator.
*
* @param iter the void_stack_iterator to be free()d.
*/
_EXPORT()
void void_stack_iterator_free(void_stack_iterator* iter);
/** Returns a pointer to the the next element in the stack.
*
* Iterates over elements starting in order from the oldest element (bottom of the stack).
*
* @param iter the void_stack_iterator used to lookup the next element.
*
* @return a pointer to the next element.
*/
_EXPORT()
const void* void_stack_iterator_next(void_stack_iterator* iter);
/* XXX: for completeness, might want to add a void_stack_iterator_first()
* function, to return iterator to first element
*/
#endif
|