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/>.
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
);
46 obstack_chunk_size(&db_obs
) = CHUNK_SIZE
;
53 /* cppcheck-suppress[nullPointerArithmetic]:
54 * False positive, imported module. */
55 return obstack_alloc(&db_obs
, size
);
58 char *nfstrsave(const char *string
) {
60 /* cppcheck-suppress[nullPointerArithmetic]:
61 * False positive, imported module. */
62 return obstack_copy0 (&db_obs
, string
, strlen(string
));
66 nfstrnsave(const char *string
, size_t size
)
69 /* cppcheck-suppress[nullPointerArithmetic]:
70 * False positive, imported module. */
71 return obstack_copy0(&db_obs
, string
, size
);
74 void nffreeall(void) {
76 /* cppcheck-suppress[nullPointerArithmetic,pointerLessThanZero]:
77 * False positive, imported module. */
78 obstack_free(&db_obs
, NULL
);