1*2fe8fb19SBen Gras /* $NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras /* 4*2fe8fb19SBen Gras * Copyright (C) 2006 Aleksey Cheusov 5*2fe8fb19SBen Gras * 6*2fe8fb19SBen Gras * This material is provided "as is", with absolutely no warranty expressed 7*2fe8fb19SBen Gras * or implied. Any use is at your own risk. 8*2fe8fb19SBen Gras * 9*2fe8fb19SBen Gras * Permission to use or copy this software for any purpose is hereby granted 10*2fe8fb19SBen Gras * without fee. Permission to modify the code and to distribute modified 11*2fe8fb19SBen Gras * code is also granted without any restrictions. 12*2fe8fb19SBen Gras */ 13*2fe8fb19SBen Gras 14*2fe8fb19SBen Gras #include <sys/cdefs.h> 15*2fe8fb19SBen Gras 16*2fe8fb19SBen Gras #if defined(LIBC_SCCS) && !defined(lint) 17*2fe8fb19SBen Gras __RCSID("$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $"); 18*2fe8fb19SBen Gras #endif /* LIBC_SCCS and not lint */ 19*2fe8fb19SBen Gras 20*2fe8fb19SBen Gras #include "namespace.h" 21*2fe8fb19SBen Gras #include <stdlib.h> 22*2fe8fb19SBen Gras #include <assert.h> 23*2fe8fb19SBen Gras #include <wchar.h> 24*2fe8fb19SBen Gras __weak_alias(wcsdup,_wcsdup)25*2fe8fb19SBen Gras__weak_alias(wcsdup,_wcsdup) 26*2fe8fb19SBen Gras 27*2fe8fb19SBen Gras wchar_t * 28*2fe8fb19SBen Gras wcsdup(const wchar_t *str) 29*2fe8fb19SBen Gras { 30*2fe8fb19SBen Gras wchar_t *copy; 31*2fe8fb19SBen Gras size_t len; 32*2fe8fb19SBen Gras 33*2fe8fb19SBen Gras _DIAGASSERT(str != NULL); 34*2fe8fb19SBen Gras 35*2fe8fb19SBen Gras len = wcslen(str) + 1; 36*2fe8fb19SBen Gras copy = malloc(len * sizeof (wchar_t)); 37*2fe8fb19SBen Gras 38*2fe8fb19SBen Gras if (!copy) 39*2fe8fb19SBen Gras return NULL; 40*2fe8fb19SBen Gras 41*2fe8fb19SBen Gras return wmemcpy(copy, str, len); 42*2fe8fb19SBen Gras } 43