Sigrid Solveig Haflínudóttirremove useless assignmentse7e0ff34 years agoHistory
89 lines · 1.5 KB · C
RawDownload
#include <sys/types.h> #include <unistd.h> #include <stdlib.h>#include <stdint.h>#include <string.h>#include <stdio.h> #include "../libc.h"#include "../fcall.h"#include "../9pfs.h"#include "../auth.h"#include "../util.h" static struct {	char *verb;	int val;} tab[] = {	{ "ok",		ARok },	{ "done",	ARdone },	{ "error",	ARerror },	{ "needkey",	ARneedkey },	{ "badkey",	ARbadkey },	{ "phase",	ARphase },	{ "toosmall",	ARtoosmall },	{ "error",	ARerror },}; static intclassify(char *buf, uint n, AuthRpc *rpc){	int i, len; 	for(i=0; i<nelem(tab); i++){		len = strlen(tab[i].verb);		if(n >= len && memcmp(buf, tab[i].verb, len) == 0 && (n==len || buf[len]==' ')){			if(n==len){				rpc->narg = 0;				rpc->arg = "";			}else{				rpc->narg = n - (len+1);				rpc->arg = (char*)buf+len+1;			}			return tab[i].val;		}	}	return ARrpcfailure;} AuthRpc*auth_allocrpc(int afd){	AuthRpc *rpc; 	rpc = emalloc(sizeof(*rpc));	if(rpc == nil)		return nil;	rpc->afd = afd;	return rpc;} voidauth_freerpc(AuthRpc *rpc){	free(rpc);} uintauth_rpc(AuthRpc *rpc, char *verb, void *a, int na){	int l, n; 	l = strlen(verb);	if(na+l+1 > AuthRpcMax){		return ARtoobig;	} 	memmove(rpc->obuf, verb, l);	rpc->obuf[l] = ' ';	memmove(rpc->obuf+l+1, a, na);	if(write(rpc->afd, rpc->obuf, l+1+na) != l+1+na)		return ARrpcfailure; 	if((n=read(rpc->afd, rpc->ibuf, AuthRpcMax)) < 0)		return ARrpcfailure;	rpc->ibuf[n] = '\0';	return classify(rpc->ibuf, n, rpc);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t