+/* Returns a number between 0 and 100 that approximates the
+ percentage of the data in READER that has already been read,
+ or -1 if this value cannot be estimated.
+
+ ftello is slow in glibc (it flushes the read buffer), so don't
+ call this function unless you need to. */
+int
+dfm_get_percent_read (const struct dfm_reader *reader)
+{
+ if (reader->file_size >= 0)
+ {
+ off_t position = ftello (reader->file);
+ if (position >= 0)
+ {
+ double p = 100.0 * position / reader->file_size;
+ return p < 0 ? 0 : p > 100 ? 100 : p;
+ }
+ }
+ return -1;
+}
+