summaryrefslogtreecommitdiffstats
path: root/src/util/share.cpp
blob: 6c436dcf8c1bc3826601c1a8bf247f37f805d280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Inkscape::Util::ptr_shared<T> - like T const *, but stronger.
 * Used to hold c-style strings for objects that are managed by the gc.
 *
 * Authors:
 *   MenTaLguY <mental@rydia.net>
 *
 * Copyright (C) 2006 MenTaLguY
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "util/share.h"
#include <glib.h>

namespace Inkscape {
namespace Util {

ptr_shared share_string(char const *string) {
    g_return_val_if_fail(string != nullptr, share_unsafe(nullptr));
    return share_string(string, std::strlen(string));
}

ptr_shared share_string(char const *string, std::size_t length) {
    g_return_val_if_fail(string != nullptr, share_unsafe(nullptr));
    char *new_string=new (GC::ATOMIC) char[length+1];
    std::memcpy(new_string, string, length);
    new_string[length] = 0;
    return share_unsafe(new_string);
}

}
}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :