2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
27 #include <atalk/errchk.h>
28 #include <atalk/util.h>
29 #include <atalk/logger.h>
30 #include <atalk/talloc.h>
31 #include <atalk/bstrlib.h>
32 #include <atalk/dalloc.h>
34 /* Use dalloc_add() macro, not this function */
35 int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size)
37 AFP_ASSERT(talloc_chunk);
39 dd->dd_talloc_array = talloc_realloc(dd, dd->dd_talloc_array, void *, talloc_array_length(dd->dd_talloc_array) + 1);
40 memcpy(talloc_chunk, obj, size);
41 dd->dd_talloc_array[talloc_array_length(dd->dd_talloc_array) - 1] = talloc_chunk;
46 /* Get number of elements, returns 0 if the structure is empty or not initialized */
47 int dalloc_size(DALLOC_CTX *d)
49 if (!d || !d->dd_talloc_array)
51 return talloc_array_length(d->dd_talloc_array);
54 void *dalloc_get(const DALLOC_CTX *d, ...)
64 type = va_arg(args, const char *);
66 if (STRCMP(type, !=, "DALLOC_CTX"))
69 while (STRCMP(type, ==, "DALLOC_CTX")) {
70 elem = va_arg(args, int);
71 AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
72 d = d->dd_talloc_array[elem];
73 type = va_arg(args, const char *);
76 elem = va_arg(args, int);
77 AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
79 p = talloc_check_name(d->dd_talloc_array[elem], type);
89 void *dalloc_value_for_key(const DALLOC_CTX *d, ...)
100 type = va_arg(args, const char *);
102 if (STRCMP(type, !=, "DALLOC_CTX"))
105 while (STRCMP(type, ==, "DALLOC_CTX")) {
106 elem = va_arg(args, int);
107 AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
108 d = d->dd_talloc_array[elem];
109 type = va_arg(args, const char *);
112 for (elem = 0; elem + 1 < talloc_array_length(d->dd_talloc_array); elem += 2) {
113 memcpy(&s, d->dd_talloc_array[elem], sizeof(char *));
114 if (STRCMP(s, ==, type)) {
115 p = d->dd_talloc_array[elem + 1];