ObjFW  Diff

Differences From Artifact [b556a211fc]:

To Artifact [fc7e1fba0a]:


66
67
68
69
70
71
72
73
74
75


76
77
78
79

80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120

121
122
123
124
125
126
127
66
67
68
69
70
71
72



73
74
75



76
77




78
79
80
81

82
83






84
85
86
87
88
89
90
91
92
93
94
95
96
97
98






99



100
101
102
103
104
105
106
107







-
-
-
+
+

-
-
-
+

-
-
-
-




-
+

-
-
-
-
-
-















-
-
-
-
-
-
+
-
-
-
+







	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (cache != NULL) {
		for (i = 0; i < cache_len; i++) {
			if (OF_UNLIKELY(cache[i] == '\n' ||
			    cache[i] == '\0')) {
				ret_c = [self allocMemoryWithSize: i + 1];
				memcpy(ret_c, cache, i);
				ret_c[i] = '\0';
				ret = [OFString stringWithCString: cache
							andLength: i];

				@try {
					tmp = [self
					    allocMemoryWithSize: cache_len -
				tmp = [self allocMemoryWithSize: cache_len -
								 i - 1];
				} @catch (OFException *e) {
					[self freeMemory: ret_c];
					@throw e;
				}
				memcpy(tmp, cache + i + 1, cache_len - i - 1);

				[self freeMemory: cache];
				cache = tmp;
				cache_len = cache_len - i - 1;
				cache_len -= i + 1;

				@try {
					ret = [OFString
					    stringWithCString: ret_c];
				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}
	}

	/* Read until we get a newline or \0 */
	tmp = [self allocMemoryWithSize: pagesize];

	for (;;) {
		if ([self atEndOfStream]) {
			[self freeMemory: tmp];

			if (cache == NULL)
				return nil;

			ret_c = [self allocMemoryWithSize: cache_len + 1];
			memcpy(ret_c, cache, cache_len);
			ret_c[cache_len] = '\0';

			@try {
				ret = [OFString stringWithCString: ret_c];
			ret = [OFString stringWithCString: cache
			} @finally {
				[self freeMemory: ret_c];
			}
						andLength: cache_len];

			[self freeMemory: cache];
			cache = NULL;
			cache_len = 0;

			return ret;
		}