diff options
| author | rsc <devnull@localhost> | 2004-04-21 03:04:30 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2004-04-21 03:04:30 +0000 |
| commit | 551445b92c1f11d4f543e96790ff29762ab1ad10 (patch) | |
| tree | 5129ea4e5cc91ff823623b080540fedcfaa72786 /src/libsunrpc/fmt.c | |
| parent | fa256eecfaf035cd6c46335452357856dc0bd9e9 (diff) | |
| download | plan9port-551445b92c1f11d4f543e96790ff29762ab1ad10.tar.gz plan9port-551445b92c1f11d4f543e96790ff29762ab1ad10.zip | |
Add sunrpc.
Diffstat (limited to 'src/libsunrpc/fmt.c')
| -rw-r--r-- | src/libsunrpc/fmt.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/libsunrpc/fmt.c b/src/libsunrpc/fmt.c new file mode 100644 index 00000000..492497d5 --- /dev/null +++ b/src/libsunrpc/fmt.c @@ -0,0 +1,64 @@ +#include <u.h> +#include <libc.h> +#include <thread.h> +#include <sunrpc.h> + +/* + * print formatters + */ +int +sunrpcfmt(Fmt *f) +{ + SunRpc *rpc; + + rpc = va_arg(f->args, SunRpc*); + sunrpcprint(f, rpc); + return 0; +} + +static SunProg **fmtProg; +static int nfmtProg; +static RWLock fmtLock; + +void +sunfmtinstall(SunProg *p) +{ + int i; + + wlock(&fmtLock); + for(i=0; i<nfmtProg; i++){ + if(fmtProg[i] == p){ + wunlock(&fmtLock); + return; + } + } + if(nfmtProg%16 == 0) + fmtProg = erealloc(fmtProg, sizeof(fmtProg[0])*(nfmtProg+16)); + fmtProg[nfmtProg++] = p; + wunlock(&fmtLock); +} + +int +suncallfmt(Fmt *f) +{ + int i; + void (*fmt)(Fmt*, SunCall*); + SunCall *c; + SunProg *p; + + c = va_arg(f->args, SunCall*); + rlock(&fmtLock); + for(i=0; i<nfmtProg; i++){ + p = fmtProg[i]; + if(p->prog == c->rpc.prog && p->vers == c->rpc.vers){ + runlock(&fmtLock); + if(c->type < 0 || c->type >= p->nproc || (fmt=p->proc[c->type].fmt) == nil) + return fmtprint(f, "unknown proc %c%d", "TR"[c->type&1], c->type>>1); + (*fmt)(f, c); + return 0; + } + } + runlock(&fmtLock); + fmtprint(f, "<sunrpc %d %d %c%d>", c->rpc.prog, c->rpc.vers, "TR"[c->type&1], c->type>>1); + return 0; +} |
