1
/* $Id: string.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
3
* innotek Portable Runtime - String Manipulation.
7
* Copyright (C) 2006-2007 innotek GmbH
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License as published by the Free Software Foundation,
13
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14
* distribution. VirtualBox OSE is distributed in the hope that it will
15
* be useful, but WITHOUT ANY WARRANTY of any kind.
19
/*******************************************************************************
21
*******************************************************************************/
22
#include <iprt/string.h>
23
#include <iprt/alloc.h>
24
#include <iprt/assert.h>
26
#include "internal/string.h"
32
* Init C runtime locale
33
* note: actually where is no need in this global var, use it only for
34
* auto run of setlocale() func.
36
/** @todo rewrite this to do setlocale() from some proper init function. */
37
static int g_RTLocaleInited = (setlocale(LC_CTYPE, "") != NULL);
41
* Free string allocated by any of the non-UCS-2 string functions.
43
* @returns iprt status code.
44
* @param pszString Pointer to buffer with string to free.
47
RTR3DECL(void) RTStrFree(char *pszString)
50
RTMemTmpFree(pszString);
55
* Allocates a new copy of the given UTF-8 string.
57
* @returns Pointer to the allocated UTF-8 string.
58
* @param pszString UTF-8 string to duplicate.
60
RTR3DECL(char *) RTStrDup(const char *pszString)
62
Assert(VALID_PTR(pszString));
63
size_t cch = strlen(pszString) + 1;
64
char *psz = (char *)RTMemAlloc(cch);
66
memcpy(psz, pszString, cch);
72
* Allocates a new copy of the given UTF-8 string.
74
* @returns iprt status code.
75
* @param ppszString Receives pointer of the allocated UTF-8 string.
76
* The returned pointer must be freed using RTStrFree().
77
* @param pszString UTF-8 string to duplicate.
79
RTR3DECL(int) RTStrDupEx(char **ppszString, const char *pszString)
81
Assert(VALID_PTR(ppszString));
82
Assert(VALID_PTR(pszString));
84
size_t cch = strlen(pszString) + 1;
85
char *psz = (char *)RTMemAlloc(cch);
88
memcpy(psz, pszString, cch);
92
return VERR_NO_MEMORY;