Home | History | Annotate | Line # | Download | only in string
wcsdup.c revision 1.4
      1  1.4       nia /*	$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 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.4       nia __RCSID("$NetBSD: wcsdup.c,v 1.4 2021/10/29 10:11:57 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.1  christos #include <wchar.h>
     24  1.1  christos 
     25  1.1  christos __weak_alias(wcsdup,_wcsdup)
     26  1.1  christos 
     27  1.1  christos wchar_t *
     28  1.1  christos wcsdup(const wchar_t *str)
     29  1.1  christos {
     30  1.1  christos 	wchar_t *copy;
     31  1.1  christos 	size_t len;
     32  1.1  christos 
     33  1.1  christos 	_DIAGASSERT(str != NULL);
     34  1.1  christos 
     35  1.1  christos 	len = wcslen(str) + 1;
     36  1.1  christos 
     37  1.4       nia 	copy = NULL;
     38  1.4       nia 	if (reallocarr(&copy, len, sizeof(wchar_t)) != 0)
     39  1.1  christos 		return NULL;
     40  1.1  christos 
     41  1.1  christos 	return wmemcpy(copy, str, len);
     42  1.1  christos }
     43