+static int find_data_chunk(uint8_t *buf, int initial_offset)
+{
+ int offset, i;
+
+ offset = initial_offset;
+ while(offset < MAX_DATA_CHUNK_OFFSET) {
+ if (!memcmp(buf + offset, "data", 4))
+ /* Skip into the samples. */
+ return offset + 8;
+ for (i = 0; i < 4; i++) {
+ if (!isalpha(buf[offset + i])
+ && !isascii(buf[offset + i])
+ && !isblank(buf[offset + i]))
+ /* Doesn't look like a chunk ID. */
+ return -1;
+ }
+ /* Skip past this chunk. */
+ offset += 8 + GUINT32_FROM_LE(*(uint32_t *)(buf + offset + 4));
+ }
+
+ return offset;
+}
+