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