From 82c24245034226967611c9d2c4f6f04b4f9db6cc Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 10 Jun 2009 17:30:52 -0400 Subject: [PATCH] Add EOF notification to the upkg export API. --- src/libupkg.c | 10 +++++++++- src/upkg.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libupkg.c b/src/libupkg.c index f2addc9..8072516 100644 --- a/src/libupkg.c +++ b/src/libupkg.c @@ -474,8 +474,13 @@ int upkg_export_seek(struct upkg_file *f, long offset, int whence) break; } - if (rc == 0) + if (rc == 0) { f->pkg->priv->last_file = f; + f->eof = 0; + } else if (f->pkg->priv->last_file == f) { + f->pkg->priv->last_file = NULL; + } + return rc; } @@ -495,5 +500,8 @@ size_t upkg_export_read(struct upkg_file *f, void *buf, size_t n) rc = fread(buf, 1, want, f->pkg->priv->f); f->offset += rc; + + if (want < n || rc < want && feof(f->pkg->priv->f)) + f->eof = 1; return rc; } diff --git a/src/upkg.h b/src/upkg.h index 2e92e85..7ef55d7 100644 --- a/src/upkg.h +++ b/src/upkg.h @@ -55,6 +55,8 @@ struct upkg { struct upkg_file { const char *name; + int eof; + struct upkg *pkg; unsigned long base, offset, len; }; -- 2.43.2