summaryrefslogtreecommitdiff
path: root/sys/src/libsunrpc/prog.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libsunrpc/prog.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libsunrpc/prog.c')
-rwxr-xr-xsys/src/libsunrpc/prog.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/sys/src/libsunrpc/prog.c b/sys/src/libsunrpc/prog.c
new file mode 100755
index 000000000..b6c46f6f0
--- /dev/null
+++ b/sys/src/libsunrpc/prog.c
@@ -0,0 +1,74 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <sunrpc.h>
+
+SunStatus
+sunCallPack(SunProg *prog, uchar *a, uchar *ea, uchar **pa, SunCall *c)
+{
+ uchar *x;
+ int (*pack)(uchar*, uchar*, uchar**, SunCall*);
+
+ if(pa == nil)
+ pa = &x;
+ if(c->type < 0 || c->type >= prog->nproc || (pack=prog->proc[c->type].pack) == nil)
+ return SunProcUnavail;
+ if((*pack)(a, ea, pa, c) < 0)
+ return SunGarbageArgs;
+ return SunSuccess;
+}
+
+SunStatus
+sunCallUnpack(SunProg *prog, uchar *a, uchar *ea, uchar **pa, SunCall *c)
+{
+ uchar *x;
+ int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
+
+ if(pa == nil)
+ pa = &x;
+ if(c->type < 0 || c->type >= prog->nproc || (unpack=prog->proc[c->type].unpack) == nil)
+ return SunProcUnavail;
+ if((*unpack)(a, ea, pa, c) < 0){
+ fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
+ return SunGarbageArgs;
+ }
+ return SunSuccess;
+}
+
+SunStatus
+sunCallUnpackAlloc(SunProg *prog, SunCallType type, uchar *a, uchar *ea, uchar **pa, SunCall **pc)
+{
+ uchar *x;
+ uint size;
+ int (*unpack)(uchar*, uchar*, uchar**, SunCall*);
+ SunCall *c;
+
+ if(pa == nil)
+ pa = &x;
+ if(type < 0 || type >= prog->nproc || (unpack=prog->proc[type].unpack) == nil)
+ return SunProcUnavail;
+ size = prog->proc[type].sizeoftype;
+ if(size == 0)
+ return SunProcUnavail;
+ c = mallocz(size, 1);
+ if(c == nil)
+ return SunSystemErr;
+ c->type = type;
+ if((*unpack)(a, ea, pa, c) < 0){
+ fprint(2, "in: %.*H unpack failed\n", (int)(ea-a), a);
+ free(c);
+ return SunGarbageArgs;
+ }
+ *pc = c;
+ return SunSuccess;
+}
+
+uint
+sunCallSize(SunProg *prog, SunCall *c)
+{
+ uint (*size)(SunCall*);
+
+ if(c->type < 0 || c->type >= prog->nproc || (size=prog->proc[c->type].size) == nil)
+ return ~0;
+ return (*size)(c);
+}