CoreFW  Check-in [ebf63ac6c8]

Overview
Comment:Add cfw_string_set_nocopy().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ebf63ac6c873f01617ec5160ac8dd5c89185ef289122492987b7e935498b150d
User & Date: js on 2012-09-29 23:22:12
Other Links: manifest | tags
Context
2012-09-30
00:25
Fix a memory leak in map. check-in: d416cefb3b user: js tags: trunk
2012-09-29
23:22
Add cfw_string_set_nocopy(). check-in: ebf63ac6c8 user: js tags: trunk
23:17
Add cfw_strndup(). check-in: 587d349f8d user: js tags: trunk
Changes

Modified src/string.c from [3b8850abd4] to [305d89e8e8].

176
177
178
179
180
181
182

183

184
185






186
187
188
189
190
191
192
193
194










195
196
197
198
199
200
201
	return string->len;
}

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);

	return true;
}











bool
cfw_string_append(CFWString *str, CFWString *append)
{
	char *new;

	if ((new = realloc(str->data, str->len + append->len + 1)) == NULL)







>

>
|
|
>
>
>
>
>
>





|



>
>
>
>
>
>
>
>
>
>







176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	return string->len;
}

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

	if (str != NULL) {
		if ((copy = cfw_strdup(cstr)) == NULL)
			return false;

		len = strlen(copy);
	} else {
		copy = NULL;
		len = 0;
	}

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

	str->data = copy;
	str->len = len;

	return true;
}

void
cfw_string_set_nocopy(CFWString *str, char *cstr, size_t len)
{
	if (str->data != NULL)
		free(str->data);

	str->data = cstr;
	str->len = len;
}

bool
cfw_string_append(CFWString *str, CFWString *append)
{
	char *new;

	if ((new = realloc(str->data, str->len + append->len + 1)) == NULL)

Modified src/string.h from [3ca4b8968d] to [2f607cb31e].

33
34
35
36
37
38
39

40
41
42
43
typedef struct CFWString CFWString;
extern CFWClass *cfw_string;
extern char* cfw_strdup(const char*);
extern char* cfw_strndup(const char*, size_t);
extern const char* cfw_string_c(CFWString*);
extern size_t cfw_string_length(CFWString*);
extern bool cfw_string_set(CFWString*, const char*);

extern bool cfw_string_append(CFWString*, CFWString*);
extern size_t cfw_string_find(CFWString*, CFWString*, cfw_range_t);

#endif







>




33
34
35
36
37
38
39
40
41
42
43
44
typedef struct CFWString CFWString;
extern CFWClass *cfw_string;
extern char* cfw_strdup(const char*);
extern char* cfw_strndup(const char*, size_t);
extern const char* cfw_string_c(CFWString*);
extern size_t cfw_string_length(CFWString*);
extern bool cfw_string_set(CFWString*, const char*);
extern void cfw_string_set_nocopy(CFWString*, char*, size_t);
extern bool cfw_string_append(CFWString*, CFWString*);
extern size_t cfw_string_find(CFWString*, CFWString*, cfw_range_t);

#endif