libixp

git clone git://oldgit.suckless.org/libixp/
Log | Files | Refs | LICENSE

commit 9a44f48eca37c7ced9c93da6002dfec2d77e32da
parent c69011d8f8f6cb023df9421a04396e4885016d6c
Author: Kris Maglione <jg@suckless.org>
Date:   Thu,  3 Sep 2009 14:28:50 -0400

Generally minor cleanup. Add some API docss.

Diffstat:
libixp/client.c | 5+++--
libixp/request.c | 7++++---
libixp/srv_util.c | 37++++++++++++++++++++++++++++++-------
mk/common.mk | 16++++++++++++----
4 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/libixp/client.c b/libixp/client.c @@ -126,9 +126,9 @@ allocmsg(IxpClient *c, int n) { * Params: * fd - A file descriptor which is already connected * to a 9P server. - * address - An address (in Plan 9 resource fomat) on + * address - An address (in Plan 9 resource fomat) at * which to connect to a 9P server. - * name - The name of the socket in the process's canonical + * name - The name of a socket in the process's canonical * namespace directory. * * Initiate a 9P connection with the server at P<address>, @@ -247,6 +247,7 @@ walk(IxpClient *c, const char *path) { return f; fail: putfid(f); + free(p); return nil; } diff --git a/libixp/request.c b/libixp/request.c @@ -27,8 +27,9 @@ static char Eduptag[] = "tag in use", Edupfid[] = "fid in use", Enofunc[] = "function not implemented", - Ebotch[] = "9P protocol botch", + Eopen[] = "fid is already open", Enofile[] = "file does not exist", + Enoread[] = "file not open for reading", Enofid[] = "fid does not exist", Enotag[] = "tag does not exist", Enotdir[] = "not a directory", @@ -203,7 +204,7 @@ handlereq(Ixp9Req *r) { return; } if(r->fid->omode != -1) { - respond(r, Ebotch); + respond(r, Eopen); return; } if(!(r->fid->qid.type&QTDIR)) { @@ -238,7 +239,7 @@ handlereq(Ixp9Req *r) { return; } if(r->fid->omode == -1 || r->fid->omode == P9_OWRITE) { - respond(r, Ebotch); + respond(r, Enoread); return; } if(!pc->srv->read) { diff --git a/libixp/srv_util.c b/libixp/srv_util.c @@ -32,6 +32,9 @@ struct IxpQueue { static IxpFileId* free_fileid; /* Utility Functions */ +/** + * Obtain an empty, reference counted IxpFileId struct. + */ IxpFileId* ixp_srv_getfile(void) { IxpFileId *f; @@ -55,6 +58,10 @@ ixp_srv_getfile(void) { return f; } +/** + * Decrease the reference count of the given IxpFileId, + * and push it onto the free list when it reaches 0; + */ void ixp_srv_freefile(IxpFileId *f) { if(--f->nref) @@ -64,14 +71,16 @@ ixp_srv_freefile(IxpFileId *f) { free_fileid = f; } -/* Increase the reference counts of the IxpFileId list */ +/** + * Increase the reference count of every IxpFileId linked + * to 'f'. + */ void ixp_srv_clonefiles(IxpFileId *f) { for(; f; f=f->next) assert(f->nref++); } -/* This should be moved to libixp */ void ixp_srv_readbuf(Ixp9Req *r, char *buf, uint len) { @@ -86,7 +95,6 @@ ixp_srv_readbuf(Ixp9Req *r, char *buf, uint len) { r->ofcall.io.count = len; } -/* This should be moved to libixp */ void ixp_srv_writebuf(Ixp9Req *r, char **buf, uint *len, uint max) { IxpFileId *f; @@ -118,6 +126,10 @@ ixp_srv_writebuf(Ixp9Req *r, char **buf, uint *len, uint max) { p[offset+count] = '\0'; } +/** + * Ensure that the data member of 'r' is null terminated, + * removing any new line from its end. + */ void ixp_srv_data2cstring(Ixp9Req *r) { char *p, *q; @@ -125,11 +137,11 @@ ixp_srv_data2cstring(Ixp9Req *r) { i = r->ifcall.io.count; p = r->ifcall.io.data; - q = memchr(p, '\0', i); if(i && p[i - 1] == '\n') i--; - if(q && q-p < i) - i = q-p; + q = memchr(p, '\0', i); + if(q) + i = q - p; p = erealloc(r->ifcall.io.data, i+1); p[i] = '\0'; @@ -285,15 +297,26 @@ ixp_pending_flush(Ixp9Req *r) { bool ixp_pending_clunk(Ixp9Req *r) { + IxpPending *p; IxpFileId *f; IxpPLink *pl; + IxpRLink *rl; IxpQueue *qu; bool more; f = r->fid->aux; pl = f->p; + + p = pl->pending; + for(rl=p->req.next; rl != &p->req; rl=rl->next) + if(rl->req->fid == pl->fid) { + respond(r, "fid in use"); + return true; + } + pl->prev->next = pl->next; pl->next->prev = pl->prev; + while((qu = pl->queue)) { pl->queue = qu->link; free(qu->dat); @@ -344,7 +367,7 @@ ixp_srv_readdir(Ixp9Req *r, IxpLookupFn lookup, void (*dostat)(IxpStat*, IxpFile f = lookup(f, nil); tf = f; - /* Note: f->tab.name == "." so we skip it */ + /* Note: The first f is ".", so we skip it. */ offset = 0; for(f=f->next; f; f=f->next) { dostat(&s, f); diff --git a/mk/common.mk b/mk/common.mk @@ -4,17 +4,25 @@ install: all MANDIRS=$(MAN)/man1 mkdirs: - for i in $(BIN) $(ETC) $(LIBDIR) $(MANDIRS) $(INCLUDE) $(DIRS); do \ - test -d $$i || echo MKDIR $$i; \ - mkdir -pm 0755 $$i; \ + for i in $(BIN) $(ETC) $(LIBDIR) $(MANDIRS) $(INCLUDE); do \ + test -d $(DESTDIR)$$i || echo MKDIR $$i; \ + mkdir -pm 0755 $(DESTDIR)$$i; \ done cleandep: echo CLEANDEP rm .depend 2>/dev/null || true +tags: + files=; \ + for f in $(OBJ); do \ + [ -f "$$f.c" ] && files="$$files $$f.c"; \ + done; \ + echo CTAGS $$files $(TAGFILES) || \ + ctags $$files $(TAGFILES) + DEP:=${shell if test -f .depend;then echo .depend;else echo /dev/null; fi} DEP!=echo /dev/null include $(DEP) -.PHONY: all options clean dist install uninstall depend cleandep +.PHONY: all options clean dist install uninstall depend cleandep tags