po: Update German man pages translation
[dpkg.git] / lib / dpkg / nfmalloc.c
blobebe35b8bdcdfcc9ef2452c156363688fa874ec34
1 /*
2 * libdpkg - Debian packaging suite library routines
3 * nfmalloc.c - non-freeing malloc, used for in-core database
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 #include <config.h>
22 #include <compat.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <obstack.h>
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.h>
32 #define obstack_chunk_alloc m_malloc
33 #define obstack_chunk_free free
35 static struct obstack db_obs;
36 static bool dbobs_init = false;
38 /* We use lots of mem, so use a large chunk. */
39 #define CHUNK_SIZE 8192
41 #define OBSTACK_INIT do { if (!dbobs_init) { nfobstack_init(); } } while (0)
43 static void nfobstack_init(void) {
44 obstack_init(&db_obs);
45 dbobs_init = true;
46 obstack_chunk_size(&db_obs) = CHUNK_SIZE;
49 void *
50 nfmalloc(size_t size)
52 OBSTACK_INIT;
53 /* cppcheck-suppress[nullPointerArithmetic]:
54 * False positive, imported module. */
55 return obstack_alloc(&db_obs, size);
58 char *nfstrsave(const char *string) {
59 OBSTACK_INIT;
60 /* cppcheck-suppress[nullPointerArithmetic]:
61 * False positive, imported module. */
62 return obstack_copy0 (&db_obs, string, strlen(string));
65 char *
66 nfstrnsave(const char *string, size_t size)
68 OBSTACK_INIT;
69 /* cppcheck-suppress[nullPointerArithmetic]:
70 * False positive, imported module. */
71 return obstack_copy0(&db_obs, string, size);
74 void nffreeall(void) {
75 if (dbobs_init) {
76 /* cppcheck-suppress[nullPointerArithmetic,pointerLessThanZero]:
77 * False positive, imported module. */
78 obstack_free(&db_obs, NULL);
79 dbobs_init = false;