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