Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / wcsdup.c
blobe0e97c0bd127de876d5670d77b16ac1b1d3e1b23
1 /*
2 FUNCTION
3 <<wcsdup>>---wide character string duplicate
5 INDEX
6 wcsdup
7 INDEX
8 _wcsdup_r
10 SYNOPSIS
11 #include <wchar.h>
12 wchar_t *wcsdup(const wchar_t *<[str]>);
14 #include <wchar.h>
15 wchar_t *_wcsdup_r(struct _reent *<[ptr]>, const wchar_t *<[str]>);
17 DESCRIPTION
18 <<wcsdup>> allocates a new wide character string using <<malloc>>,
19 and copies the content of the argument <[str]> into the newly
20 allocated string, thus making a copy of <[str]>.
22 RETURNS
23 <<wcsdup>> returns a pointer to the copy of <[str]> if enough
24 memory for the copy was available. Otherwise it returns NULL
25 and errno is set to ENOMEM.
27 PORTABILITY
28 POSIX-1.2008
30 QUICKREF
31 wcsdup
34 #include <reent.h>
35 #include <stdlib.h>
36 #include <wchar.h>
38 wchar_t *
39 _wcsdup_r (struct _reent *p, const wchar_t *str)
41 size_t len = wcslen (str) + 1;
42 wchar_t *copy = _malloc_r (p, len * sizeof (wchar_t));
43 if (copy)
44 wmemcpy (copy, str, len);
45 return copy;
48 #ifndef _REENT_ONLY
50 wchar_t *
51 wcsdup (const wchar_t *str)
53 return _wcsdup_r (_REENT, str);
56 #endif /* !_REENT_ONLY */