112e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala/*	$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $	*/
212e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
312e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala/*
412e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * Copyright (C) 2006 Aleksey Cheusov
512e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala *
612e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * This material is provided "as is", with absolutely no warranty expressed
712e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * or implied. Any use is at your own risk.
812e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala *
912e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * Permission to use or copy this software for any purpose is hereby granted
1012e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * without fee. Permission to modify the code and to distribute modified
1112e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala * code is also granted without any restrictions.
1212e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala */
1312e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
1412e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#ifndef HAVE_WCSDUP
1512e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
1612e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#include "config.h"
1712e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
1812e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#if defined(LIBC_SCCS) && !defined(lint)
1912e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala__RCSID("$NetBSD: wcsdup.c,v 1.3 2008/05/26 13:17:48 haad Exp $");
2012e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#endif /* LIBC_SCCS and not lint */
2112e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
2212e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#include <stdlib.h>
2312e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#include <assert.h>
2412e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#include <wchar.h>
2512e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
2612e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fialawchar_t *
2712e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fialawcsdup(const wchar_t *str)
2812e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala{
2912e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	wchar_t *copy;
3012e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	size_t len;
3112e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
3212e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	_DIAGASSERT(str != NULL);
3312e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
3412e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	len = wcslen(str) + 1;
3512e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	copy = malloc(len * sizeof (wchar_t));
3612e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
3712e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	if (!copy)
3812e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala		return NULL;
3912e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
4012e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala	return wmemcpy(copy, str, len);
4112e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala}
4212e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala
4312e21689bc88a77c7b5b9b220fec31e049e5ec0fTodd Fiala#endif
44