1 /* $NetBSD: pool.c,v 1.1.1.1 2008/12/22 00:18:35 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of the device-mapper userspace tools. 8 * 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. 12 * 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 16 */ 17 18 #include "dmlib.h" 19 20 #ifdef DEBUG_POOL 21 #include "pool-debug.c" 22 #else 23 #include "pool-fast.c" 24 #endif 25 26 char *dm_pool_strdup(struct dm_pool *p, const char *str) 27 { 28 char *ret = dm_pool_alloc(p, strlen(str) + 1); 29 30 if (ret) 31 strcpy(ret, str); 32 33 return ret; 34 } 35 36 char *dm_pool_strndup(struct dm_pool *p, const char *str, size_t n) 37 { 38 char *ret = dm_pool_alloc(p, n + 1); 39 40 if (ret) { 41 strncpy(ret, str, n); 42 ret[n] = '\0'; 43 } 44 45 return ret; 46 } 47 48 void *dm_pool_zalloc(struct dm_pool *p, size_t s) 49 { 50 void *ptr = dm_pool_alloc(p, s); 51 52 if (ptr) 53 memset(ptr, 0, s); 54 55 return ptr; 56 } 57