-
- if (is_packetized) {
- ret = ctf_metadata_decoder_packetized_file_stream_to_buf(
- metadata_fp, &metadata_text, bo, NULL, NULL,
- log_level, NULL);
- if (ret) {
- BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
- "Cannot decode packetized metadata file: path=\"%s\"",
- path);
- goto error;
- }
- } else {
- long filesize;
-
- ret = fseek(metadata_fp, 0, SEEK_END);
- if (ret) {
- BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(self_comp_class,
- "Failed to seek to the end of the metadata file",
- ": path=\"%s\"", path);
- goto error;
- }
- filesize = ftell(metadata_fp);
- if (filesize < 0) {
- BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(self_comp_class,
- "Failed to get the current position in the metadata file",
- ": path=\"%s\"", path);
- goto error;
- }
- rewind(metadata_fp);
- metadata_text = malloc(filesize + 1);
- if (!metadata_text) {
- BT_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp_class,
- "Cannot allocate buffer for metadata text.");
- goto error;
- }
-
- if (fread(metadata_text, filesize, 1, metadata_fp) != 1) {
- BT_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO(self_comp_class,
- "Cannot read metadata file", ": path=\"%s\"",
- path);
- goto error;
- }
-
- metadata_text[filesize] = '\0';