]> git.draconx.ca Git - upkg.git/blobdiff - src/libupkg.c
Implement file positioning functions for upkg exports.
[upkg.git] / src / libupkg.c
index 0dc2adeca76aab05336acddff6e655197c272044..64b00d27818db40a3d6628bb8b621059d2e57f1b 100644 (file)
@@ -415,6 +415,37 @@ void upkg_export_close(struct upkg_file *f)
        free(f);
 }
 
+long upkg_export_tell(struct upkg_file *f)
+{
+       return f->offset;
+}
+
+int upkg_export_seek(struct upkg_file *f, long offset, int whence)
+{
+       int rc = EOF;
+
+       switch (whence) {
+       case SEEK_CUR:
+               offset = f->offset + offset;
+       case SEEK_SET:
+               if (offset < 0 || offset > f->len)
+                       return EOF;
+               rc = fseek(f->pkg->priv->f, f->base + offset, SEEK_SET);
+               break;
+       case SEEK_END:
+               offset = -offset;
+               if (offset < 0 || offset > f->len)
+                       return EOF;
+               offset = f->len - offset;
+               rc = fseek(f->pkg->priv->f, f->base + offset, SEEK_SET);
+               break;
+       }
+
+       if (rc == 0)
+               f->pkg->priv->last_file = f;
+       return rc;
+}
+
 size_t upkg_export_read(struct upkg_file *f, void *buf, size_t n)
 {
        size_t want = MIN(n, f->len - f->offset);