int current_index = 0;
int current_max_size = PLAYLIST_ARRAY_SIZE;
int tmp_str_len = 0;
- char *buf = NULL;
char *tmp_buf = NULL;
char *tmp_str = NULL;
char repl_item[MAX_QUERY_SIZE] = {0, };
return MEDIA_CONTENT_ERROR_NONE;
}
- if (file_size > 0)
- buf = malloc(file_size + 1);
-
- if (buf == NULL) {
- media_content_error("Out of Memory");
- fclose(fp);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
-
- tmp_buf = buf;
-
- if (fread(buf, file_size, 1, fp) != 1) {
- fclose(fp);
- SAFE_FREE(buf);
- media_content_stderror("fread fail");
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
- }
- buf[file_size] = 0;
- fclose(fp);
-
*item_list = calloc(current_max_size, sizeof(char*));
- tmp_str = malloc(MAX_TMP_STR);
+ tmp_str = malloc(MAX_QUERY_SIZE);
if (tmp_str == NULL || *item_list == NULL) {
+ fclose(fp);
SAFE_FREE(*item_list);
- SAFE_FREE(buf);
SAFE_FREE(tmp_str);
media_content_error("Out of Memory");
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
+ memset(tmp_str, 0, sizeof(MAX_QUERY_SIZE));
- char format[25];
- snprintf(format, 25, "%%%d[^\n]", MAX_TMP_STR - 1);
-
- while ((sscanf(tmp_buf, format, tmp_str) == 1) || (*tmp_buf == '\n')) {
- if (*tmp_buf == '\n') {
- tmp_buf += 1;
-
- if (tmp_buf < (buf + file_size))
- continue;
- else
- break;
- }
-
+ while (fgets(tmp_str, MAX_QUERY_SIZE, fp) != NULL) {
memset(repl_item, 0, sizeof(repl_item));
_media_content_replace_path(tmp_str, repl_item);
tmp_str_len = strlen(repl_item);
+ if (repl_item[tmp_str_len - 1] == '\n')
+ repl_item[tmp_str_len - 1] = '\0';
+
SAFE_FREE(tmp_str);
- tmp_str = strndup(repl_item, tmp_str_len);
+ tmp_str = strndup(repl_item, strlen(repl_item));
if (tmp_str[0] != '#') {
if (!(current_index < (current_max_size - 1))) {
char **tmp_ptr = calloc(current_max_size, sizeof(char*));
if (tmp_ptr == NULL) {
__media_playlist_destroy_import_item(*item_list, current_index);
- SAFE_FREE(buf);
SAFE_FREE(tmp_str);
media_content_error("Out of Memory");
+ fclose(fp);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
memmove(tmp_ptr, *item_list, sizeof(char*) * current_index);
(*item_list)[current_index] = malloc(tmp_str_len + 1);
if ((*item_list)[current_index] == NULL) {
__media_playlist_destroy_import_item(*item_list, current_index);
- SAFE_FREE(buf);
SAFE_FREE(tmp_str);
media_content_error("Out of Memory");
+ fclose(fp);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
memset((*item_list)[current_index], 0, tmp_str_len + 1);
}
*item_count = current_index;
-
- SAFE_FREE(buf);
SAFE_FREE(tmp_str);
+ fclose(fp);
return MEDIA_CONTENT_ERROR_NONE;
}