libbio: add aux pointer to bio

This allows us to attach additional context
to the biobuf so can read from some sort of
data structure without a global variable.
This commit is contained in:
Ori Bernstein 2020-11-01 11:42:54 -08:00
parent b5086c1863
commit dbd54342fd
2 changed files with 12 additions and 1 deletions

View file

@ -34,6 +34,7 @@ struct Biobufhdr
uchar* gbuf; /* pointer to good data in buf */ uchar* gbuf; /* pointer to good data in buf */
void (*errorf)(char *); /* called on error if not nil */ void (*errorf)(char *); /* called on error if not nil */
int (*iof)(Biobufhdr*, void *, long); /* called to do i/o */ int (*iof)(Biobufhdr*, void *, long); /* called to do i/o */
void *aux; /* user data */
}; };
struct Biobuf struct Biobuf

View file

@ -1,6 +1,6 @@
.TH BIO 2 .TH BIO 2
.SH NAME .SH NAME
Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal, Biofn \- buffered input/output
.SH SYNOPSIS .SH SYNOPSIS
.ta \w'Biobuf* 'u .ta \w'Biobuf* 'u
.B #include <u.h> .B #include <u.h>
@ -9,6 +9,16 @@ Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc,
.br .br
.B #include <bio.h> .B #include <bio.h>
.PP .PP
.ft L
.nf
.ta \w' 'u +\w' 'u +\w' 'u +\w' 'u +\w' 'u
typedef struct Biobufhdr Biobufhdr;
struct Biobufhdr {
void *aux; /* user data */
... /* internals */
};
.fi
.PP
.B .B
Biobuf* Bopen(char *file, int mode) Biobuf* Bopen(char *file, int mode)
.PP .PP