Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / libdm / mm / pool.c
blob883d9629619bf358a40d94e15043d818a439c224
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
7 * This file is part of the device-mapper userspace tools.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "dmlib.h"
20 /* FIXME: thread unsafe */
21 static DM_LIST_INIT(_dm_pools);
22 void dm_pools_check_leaks(void);
24 #ifdef DEBUG_POOL
25 #include "pool-debug.c"
26 #else
27 #include "pool-fast.c"
28 #endif
30 char *dm_pool_strdup(struct dm_pool *p, const char *str)
32 char *ret = dm_pool_alloc(p, strlen(str) + 1);
34 if (ret)
35 strcpy(ret, str);
37 return ret;
40 char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n)
42 char *ret = dm_pool_alloc(p, n + 1);
44 if (ret) {
45 strncpy(ret, str, n);
46 ret[n] = '\0';
49 return ret;
52 void *dm_pool_zalloc(struct dm_pool *p, size_t s)
54 void *ptr = dm_pool_alloc(p, s);
56 if (ptr)
57 memset(ptr, 0, s);
59 return ptr;
62 void dm_pools_check_leaks(void)
64 struct dm_pool *p;
66 if (dm_list_empty(&_dm_pools))
67 return;
69 log_error("You have a memory leak (not released memory pool):");
70 dm_list_iterate_items(p, &_dm_pools) {
71 #ifdef DEBUG_POOL
72 log_error(" [%p] %s (%u bytes)",
73 p->orig_pool,
74 p->name, p->stats.bytes);
75 #else
76 log_error(" [%p]", p);
77 #endif