chiark / gitweb /
protogen: disorder_new_tracks().
[disorder] / lib / hreader.h
index 46f8bd918b9e9ba9e17d1e821af8ed2c7509762a..90431c1380fa557795ab7423ef2bf253767925ea 100644 (file)
@@ -28,7 +28,7 @@
  * Allows files to be read without holding them open.
  */
 struct hreader {
-  const char *path;            /* file to read */
+  char *path;                   /* file to read */
   off_t size;                   /* file size */
   off_t read_offset;            /* for next hreader_read() */
   off_t buf_offset;             /* offset of start of buffer */
@@ -44,6 +44,11 @@ struct hreader {
  */
 int hreader_init(const char *path, struct hreader *h);
 
+/** @brief Close a hands-off reader
+ * @param h Reader to close
+ */
+void hreader_close(struct hreader *h);
+
 /** @brief Read some bytes
  * @param h Reader to read from
  * @param buffer Where to store bytes
@@ -69,6 +74,26 @@ int hreader_pread(struct hreader *h, void *buffer, size_t n, off_t offset);
  */
 off_t hreader_seek(struct hreader *h, off_t offset, int whence);
 
+/** @brief Return file size
+ * @param h Reader to find size of
+ * @return Size in bytes
+ */
+static inline off_t hreader_size(const struct hreader *h) {
+  return h->size;
+}
+
+/** @brief Test for end of file
+ * @param h Reader to test
+ * @return 1 at eof, 0 otherwise
+ *
+ * This tells you whether the next read will return 0 bytes, rather than
+ * whether the last read reached end of file.  So it is slightly different to
+ * feof().
+ */
+static inline int hreader_eof(const struct hreader *h) {
+  return h->read_offset == h->size;
+}
+
 #endif /* HREADER_H */
 
 /*