summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-18 15:10:07 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-07-18 15:10:07 (GMT)
commitb0c0f377b5d4eb3344f22cd87171f83085eaa994 (patch) (side-by-side diff)
tree9c0bdece282348b0fe5f0a4de3fbbcc0bdffe126
parent24b9e009c9c2eef1b6d1accb3ac7ccc53c44c0a8 (diff)
downloadruncap-b0c0f377b5d4eb3344f22cd87171f83085eaa994.tar.gz
runcap-b0c0f377b5d4eb3344f22cd87171f83085eaa994.tar.bz2
Minor change
* runcap.h (filecapture) <fc_linestart>: Rename to fc_cur. All uses updated. * runcap.c (filecapture_put): Use fc_cur as current pointer and fc_level as the limit, for consistency. (runcap_init): Initialize fc_cur.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--getc.c6
-rw-r--r--runcap.c24
-rw-r--r--runcap.h2
-rw-r--r--seek.c4
-rw-r--r--tell.c2
5 files changed, 20 insertions, 18 deletions
diff --git a/getc.c b/getc.c
index 3c203d9..fce14ea 100644
--- a/getc.c
+++ b/getc.c
@@ -34,7 +34,7 @@ runcap_getc(struct runcap *rc, int stream, char *cp)
if (!fp)
return -1;
- if (fp->fc_level == fp->fc_linestart) {
+ if (fp->fc_level == fp->fc_cur) {
if (fp->fc_tmpfd != -1) {
ssize_t r = read(fp->fc_tmpfd, fp->fc_base,
fp->fc_size);
@@ -43,12 +43,12 @@ runcap_getc(struct runcap *rc, int stream, char *cp)
else if (r == 0)
return 0;
fp->fc_level = r;
- fp->fc_linestart = 0;
+ fp->fc_cur = 0;
} else {
return 0;
}
}
- *cp = fp->fc_base[fp->fc_linestart++];
+ *cp = fp->fc_base[fp->fc_cur++];
return 1;
}
diff --git a/runcap.c b/runcap.c
index 9dcefa1..9abc492 100644
--- a/runcap.c
+++ b/runcap.c
@@ -39,7 +39,7 @@ filecapture_alloc(struct filecapture *fc, size_t size)
fc->fc_leng = 0;
fc->fc_level = 0;
fc->fc_nlines = 0;
- fc->fc_linestart = 0;
+ fc->fc_cur = 0;
fc->fc_tmpfd = -1;
fc->fc_fd = -1;
return 0;
@@ -65,7 +65,7 @@ filecapture_reset(struct filecapture *fc)
fc->fc_leng = 0;
fc->fc_level = 0;
fc->fc_nlines = 0;
- fc->fc_linestart = 0;
+ fc->fc_cur = 0;
if (fc->fc_tmpfd >= 0) {
close(fc->fc_tmpfd);
@@ -126,7 +126,7 @@ filecapture_flush(struct filecapture *fc)
if (res)
return -1;
fc->fc_level = 0;
- fc->fc_linestart = 0;
+ fc->fc_cur = 0;
return 0;
}
@@ -154,10 +154,10 @@ filecapture_get(struct filecapture *fc, int *feof)
fc->fc_leng++;
if (c == '\n') {
if (fc->fc_linemon)
- fc->fc_linemon(fc->fc_base + fc->fc_linestart,
- fc->fc_level - fc->fc_linestart,
+ fc->fc_linemon(fc->fc_base + fc->fc_cur,
+ fc->fc_level - fc->fc_cur,
fc->fc_monarg);
- fc->fc_linestart = fc->fc_level;
+ fc->fc_cur = fc->fc_level;
fc->fc_nlines++;
}
return 0;
@@ -166,17 +166,17 @@ filecapture_get(struct filecapture *fc, int *feof)
static int
filecapture_put(struct filecapture *fc, int *feof)
{
- if (fc->fc_level < fc->fc_size) {
- int n = write(fc->fc_fd, &fc->fc_base[fc->fc_level], 1);
+ if (fc->fc_cur < fc->fc_level) {
+ int n = write(fc->fc_fd, &fc->fc_base[fc->fc_cur], 1);
if (n == -1)
return -1;
if (n == 0) {
errno = ENOSPC;
return -1;
}
- fc->fc_level++;
+ fc->fc_cur++;
}
- *feof = fc->fc_level == fc->fc_size;
+ *feof = fc->fc_cur == fc->fc_level;
return 0;
}
@@ -428,7 +428,9 @@ runcap_init(struct runcap *rc, int flags)
errno = EINVAL;
return -1;
}
- rc->rc_cap[RUNCAP_STDIN].fc_level = 0;
+ rc->rc_cap[RUNCAP_STDIN].fc_level =
+ rc->rc_cap[RUNCAP_STDIN].fc_size;
+ rc->rc_cap[RUNCAP_STDIN].fc_cur = 0;
} else if (filecapture_init(&rc->rc_cap[RUNCAP_STDIN], 0))
return -1;
diff --git a/runcap.h b/runcap.h
index 517cd43..c57f2e1 100644
--- a/runcap.h
+++ b/runcap.h
@@ -22,7 +22,7 @@ struct filecapture
size_t fc_size; /* size of the buffer */
off_t fc_leng; /* total length of captured data */
size_t fc_nlines; /* number of captured lines */
- size_t fc_linestart; /* current offset in buffer */
+ size_t fc_cur; /* current offset in buffer */
char * fc_base; /* buffer space */
size_t fc_level; /* number of characters currently in buffer */
void (*fc_linemon) (const char *, size_t, void *);
diff --git a/seek.c b/seek.c
index 5b5b111..b69cfe0 100644
--- a/seek.c
+++ b/seek.c
@@ -55,12 +55,12 @@ runcap_seek(struct runcap *rc, int stream, off_t off, int whence)
cur -= fp->fc_level;
if (cur <= off && off <= cur + fp->fc_level) {
- fp->fc_linestart = off - cur;
+ fp->fc_cur = off - cur;
} else if (fp->fc_tmpfd != -1) {
if (lseek(fp->fc_tmpfd, off, SEEK_SET) == -1)
return -1;
fp->fc_level = 0;
- fp->fc_linestart = 0;
+ fp->fc_cur = 0;
} else {
errno = EINVAL;
return -1;
diff --git a/tell.c b/tell.c
index 7044ddd..47729ed 100644
--- a/tell.c
+++ b/tell.c
@@ -36,6 +36,6 @@ runcap_tell(struct runcap *rc, int stream)
} else
off = 0;
- return off + fp->fc_linestart;
+ return off + fp->fc_cur;
}

Return to:

Send suggestions and report system problems to the System administrator.