CoreFW  Diff

Differences From Artifact [0d338be9da]:

To Artifact [14e8b0fd1e]:


23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39



















40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include <stdint.h>
#include <string.h>


#include "object.h"
#include "string.h"
#include "hash.h"

struct CFWString {
	CFWObject obj;
	char *data;
	size_t len;
};




















static bool
ctor(void *ptr, va_list args)
{
	CFWString *str = ptr;
	const char *cstr = va_arg(args, const char*);

	if (cstr != NULL) {
		str->data = NULL;
		if ((str->data = strdup(cstr)) == NULL)
			return false;

		str->len = strlen(cstr);
	} else {
		str->data = NULL;
		str->len = 0;
	}







>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>

#include "object.h"
#include "string.h"
#include "hash.h"

struct CFWString {
	CFWObject obj;
	char *data;
	size_t len;
};

char*
cfw_strdup(const char *s)
{
	char *copy;
	size_t len;

	len = strlen(s);

	if ((copy = malloc(len + 1)) == NULL) {
		errno = ENOMEM;
		return NULL;
	}

	memcpy(copy, s, len);
	copy[len] = 0;

	return copy;
}

static bool
ctor(void *ptr, va_list args)
{
	CFWString *str = ptr;
	const char *cstr = va_arg(args, const char*);

	if (cstr != NULL) {
		str->data = NULL;
		if ((str->data = cfw_strdup(cstr)) == NULL)
			return false;

		str->len = strlen(cstr);
	} else {
		str->data = NULL;
		str->len = 0;
	}
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
}

bool
cfw_string_set(CFWString *str, const char *cstr)
{
	char *copy;

	if ((copy = strdup(cstr)) == NULL)
		return false;

	if (str->data != NULL)
		free(str->data);

	str->data = copy;
	str->len = strlen(copy);







|







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
}

bool
cfw_string_set(CFWString *str, const char *cstr)
{
	char *copy;

	if ((copy = cfw_strdup(cstr)) == NULL)
		return false;

	if (str->data != NULL)
		free(str->data);

	str->data = copy;
	str->len = strlen(copy);