CoreFW  Diff

Differences From Artifact [305d89e8e8]:

To Artifact [6218da6faa]:


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
77
78
79
80
81
82
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
77

78

79

80
81
82
83
84
85
86







+
+
+
+
+
+
+
+
+
+
+









-
+
-

-













-
-
-
-
+

-
+
-

-







#include "hash.h"

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

size_t
cfw_strnlen(const char *s, size_t max)
{
	size_t i = 0;

	for (i = 0; i < max && *s != '\0'; s++)
		i++;

	return i;
}

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

	len = strlen(s);

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

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

	return copy;
}

char*
cfw_strndup(const char *s, size_t max)
{
	char *copy;
	size_t len;

	len = strlen(s);

	if (len > max)
		len = max;
	len = cfw_strnlen(s, max);

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

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

	return copy;
}