OSDN Git Service

Merge branch 'master' of https://github.com/hengband/hengband
[hengbandforosx/hengbandosx.git] / src / term / z-virt.cpp
1 /* File: z-virt.c */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison
5  *
6  * This software may be copied and distributed for educational, research,
7  * and not for profit purposes provided that this copyright and statement
8  * are included in all such copies.
9  */
10
11 /* Purpose: Memory management routines -BEN- */
12
13 #include "term/z-virt.h"
14 #include <cstring>
15
16 /*!
17  * @brief str の複製を返す。戻り値は使用後に string_free() で解放すること。
18  *
19  * nullptr が渡された場合、nullptr を返す。
20  */
21 const char *string_make(const char *str)
22 {
23     if (!str) {
24         return nullptr;
25     }
26
27     const auto bufsize = std::strlen(str) + 1;
28     auto *const buf = new char[bufsize];
29     std::strcpy(buf, str);
30
31     return buf;
32 }
33
34 /*!
35  * @brief string_make() で割り当てたバッファを解放する。
36  * @return 常に 0
37  *
38  * nullptr が渡された場合、何もせず 0 を返す。
39  */
40 int string_free(const char *str)
41 {
42     if (!str) {
43         return 0;
44     }
45
46     delete[] str;
47
48     return 0;
49 }