source: trunk/libs/newlib/src/newlib/libc/string/wcsdup.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.0 KB
Line 
1/*
2FUNCTION
3        <<wcsdup>>---wide character string duplicate
4       
5INDEX
6        wcsdup
7INDEX
8        _wcsdup_r
9
10SYNOPSIS
11        #include <wchar.h>
12        wchar_t *wcsdup(const wchar_t *<[str]>);
13
14        #include <wchar.h>
15        wchar_t *_wcsdup_r(struct _reent *<[ptr]>, const wchar_t *<[str]>);
16
17DESCRIPTION
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]>.
21
22RETURNS
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.
26
27PORTABILITY
28POSIX-1.2008
29
30QUICKREF
31        wcsdup
32*/
33
34#include <reent.h>
35#include <stdlib.h>
36#include <wchar.h>
37
38wchar_t *
39_wcsdup_r (struct _reent *p, const wchar_t *str)
40{
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;
46}
47
48#ifndef _REENT_ONLY
49
50wchar_t *
51wcsdup (const wchar_t *str)
52{
53  return _wcsdup_r (_REENT, str);
54}
55
56#endif /* !_REENT_ONLY */
Note: See TracBrowser for help on using the repository browser.