aboutsummaryrefslogtreecommitdiff
path: root/runcap.h
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-18 17:50:34 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-07-18 17:50:34 +0300
commit24b9e009c9c2eef1b6d1accb3ac7ccc53c44c0a8 (patch)
treefbd53229d5f87f9a99cbd64a89ac4fb1d06bd7ad /runcap.h
parent3488a182f66e35b091f441b9201ad43ad6d0f1ac (diff)
downloadruncap-24b9e009c9c2eef1b6d1accb3ac7ccc53c44c0a8.tar.gz
runcap-24b9e009c9c2eef1b6d1accb3ac7ccc53c44c0a8.tar.bz2
Add missing API calls, provide testsuite
Diffstat (limited to 'runcap.h')
-rw-r--r--runcap.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/runcap.h b/runcap.h
index b677f05..517cd43 100644
--- a/runcap.h
+++ b/runcap.h
@@ -16,22 +16,23 @@
#ifndef _RUNCAP_H_
# define _RUNCAP_H_ 1
struct filecapture
{
- size_t fc_size;
- size_t fc_leng;
- size_t fc_nlines;
- size_t fc_linestart;
- char * fc_base;
- size_t fc_level;
+ 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 */
+ char * fc_base; /* buffer space */
+ size_t fc_level; /* number of characters currently in buffer */
void (*fc_linemon) (const char *, size_t, void *);
- void *fc_monarg;
- int fc_tmpfd;
- int fc_fd;
+ /* Line monitor function */
+ void *fc_monarg; /* Line monitor argument */
+ int fc_tmpfd; /* Storage file descriptor */
+ int fc_fd; /* Input descriptor */
};
#define FC_BUFSIZE 4096
enum {
RUNCAP_STDIN,
@@ -63,7 +64,37 @@ struct runcap
int filecapture_init(struct filecapture *fc, size_t size);
void filecapture_free(struct filecapture *fc);
int runcap(struct runcap *rc, int flags);
void runcap_free(struct runcap *rc);
+static inline struct filecapture *
+runcap_filecapture(struct runcap *rc, int stream)
+{
+ struct filecapture *fp;
+
+ if (stream != RUNCAP_STDOUT && stream != RUNCAP_STDERR) {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ fp = &rc->rc_cap[stream];
+
+ if (!fp->fc_base || fp->fc_size == 0) {
+ errno = EINVAL;
+ return NULL;
+ }
+ return fp;
+}
+
+int runcap_getc(struct runcap *rc, int stream, char *cp);
+ssize_t runcap_getline(struct runcap *rc, int stream, char **pstr, size_t *psize);
+off_t runcap_tell(struct runcap *rc, int stream);
+int runcap_seek(struct runcap *rc, int stream, off_t off, int whence);
+
+static inline int
+runcap_rewind(struct runcap *rc, int stream)
+{
+ return runcap_seek(rc, stream, 0, 0);
+}
+
#endif

Return to:

Send suggestions and report system problems to the System administrator.