VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/string.cpp@ 7389

Last change on this file since 7389 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/* $Id: string.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - String Manipulation.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <iprt/string.h>
32#include <iprt/alloc.h>
33#include <iprt/assert.h>
34#include <iprt/err.h>
35#include "internal/string.h"
36
37#include <locale.h>
38
39
40/**
41 * Init C runtime locale
42 * note: actually where is no need in this global var, use it only for
43 * auto run of setlocale() func.
44 */
45/** @todo rewrite this to do setlocale() from some proper init function. */
46static int g_RTLocaleInited = (setlocale(LC_CTYPE, "") != NULL);
47
48
49/**
50 * Free string allocated by any of the non-UCS-2 string functions.
51 *
52 * @returns iprt status code.
53 * @param pszString Pointer to buffer with string to free.
54 * NULL is accepted.
55 */
56RTR3DECL(void) RTStrFree(char *pszString)
57{
58 if (pszString)
59 RTMemTmpFree(pszString);
60}
61
62
63/**
64 * Allocates a new copy of the given UTF-8 string.
65 *
66 * @returns Pointer to the allocated UTF-8 string.
67 * @param pszString UTF-8 string to duplicate.
68 */
69RTR3DECL(char *) RTStrDup(const char *pszString)
70{
71 Assert(VALID_PTR(pszString));
72 size_t cch = strlen(pszString) + 1;
73 char *psz = (char *)RTMemAlloc(cch);
74 if (psz)
75 memcpy(psz, pszString, cch);
76 return psz;
77}
78
79
80/**
81 * Allocates a new copy of the given UTF-8 string.
82 *
83 * @returns iprt status code.
84 * @param ppszString Receives pointer of the allocated UTF-8 string.
85 * The returned pointer must be freed using RTStrFree().
86 * @param pszString UTF-8 string to duplicate.
87 */
88RTR3DECL(int) RTStrDupEx(char **ppszString, const char *pszString)
89{
90 Assert(VALID_PTR(ppszString));
91 Assert(VALID_PTR(pszString));
92
93 size_t cch = strlen(pszString) + 1;
94 char *psz = (char *)RTMemAlloc(cch);
95 if (psz)
96 {
97 memcpy(psz, pszString, cch);
98 *ppszString = psz;
99 return VINF_SUCCESS;
100 }
101 return VERR_NO_MEMORY;
102}
103
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette