+ /* Deal with empty files */
+ if (!filestats.st_size) {
+ if (file_stream->parent.trace_packet_header
+ || file_stream->parent.stream_packet_context) {
+ /*
+ * We expect a trace packet header and/or stream packet
+ * context. Since a trace needs to have at least one
+ * packet, empty files are therefore not accepted.
+ */
+ fprintf(stderr, "[error] Encountered an empty file, but expecting a trace packet header.\n");
+ return -EINVAL;
+ } else {
+ /*
+ * Without trace packet header nor stream packet
+ * context, a one-packet trace can indeed be empty. This
+ * is only valid if there is only one stream class: 0.
+ */
+ ret = stream_assign_class(td, file_stream, 0);
+ if (ret)
+ return ret;
+ return 0;
+ }
+ }
+