char **lines;
int i;
char lap_address[BT_LOWER_ADDRESS_LENGTH + 1] = {0,};
- char *temp_buffer;
FILE *fp;
long size;
size_t result;
+ int count = 0;
+ char *token;
BT_DBG("+\n");
return FALSE;
}
- lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
- g_free(buffer);
-
- if (lines == NULL)
+ for (char *p = buffer; (p = strstr(p, "\r\n")); p += 2)
+ count++;
+ lines = g_malloc0(sizeof(char *) * (count + 1));
+ if (lines == NULL) {
+ g_free(buffer);
return FALSE;
+ }
- /* Write the data and insert new device data */
- for (i = 0; lines[i] != NULL; i++) {
- if (g_str_has_prefix(lines[i], "AddressBlocklist")) {
- temp_buffer = g_strconcat(lines[i], lap_address, NULL);
+ token = strtok(buffer, "\r\n");
+ for (i = 0; i < count; i++) {
+ if (g_str_has_prefix(token, "AddressBlocklist"))
+ lines[i] = g_strconcat(token, lap_address, NULL);
+ else
+ lines[i] = g_strdup(token);
+
+ if (i == count - 1) {
g_free(lines[i]);
- lines[i] = temp_buffer;
+ lines[i] = g_strconcat(token, "\r\n", NULL);
}
+ token = strtok(NULL, "\r\n");
}
+ g_free(buffer);
+
buffer = g_strjoinv(BT_AGENT_NEW_LINE, lines);
g_strfreev(lines);
/* Fix : NULL_RETURNS */