libixp

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

commit d80625259636e5b3935df4f91248ea30153a600f
parent 868f1cd4bcd9f87e6c93cfc928988b2be03a981f
Author: Kris Maglione <kris@suckless.org>
Date:   Wed, 23 Jun 2010 13:53:42 -0400

Add ixp_pending_print and ixp_pending_vprint.

Diffstat:
debian/copyright | 2--
debian/copyright | 21+++++++++++++++++++++
include/ixp.h | 23+++++++++++++----------
include/ixp_srvutil.h | 8+++++---
lib/libixp/convert.c | 16++++++++--------
lib/libixp/srv_util.c | 30+++++++++++++++++++++++++++++-
6 files changed, 76 insertions(+), 24 deletions(-)

diff --git a/debian/copyright b/debian/copyright @@ -1 +0,0 @@ -../LICENSE- \ No newline at end of file diff --git a/debian/copyright b/debian/copyright @@ -0,0 +1,21 @@ + +© 2005-2006 Anselm R. Garbe <garbeam@gmail.com> +© 2006-2010 Kris Maglione <maglione.k at Gmail> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/include/ixp.h b/include/ixp.h @@ -30,14 +30,17 @@ * of libixp with a different API version than it was compiled * against. */ -#define IXP_API 129 +#define IXP_API 134 +#define _IXP_ASSERT_VERSION ixp_version_ ## 134 ## _required + #ifndef IXP_NEEDAPI #define IXP_NEEDAPI IXP_API #endif + #ifndef IXP_MAXAPI #define IXP_MAXAPI IXP_API #endif -#define _IXP_ASSERT_VERSION ixp_version_##129##_required + #define IXP_ASSERT_VERSION do _IXP_ASSERT_VERSION = 0; while(0) extern int _IXP_ASSERT_VERSION; @@ -46,19 +49,22 @@ extern int _IXP_ASSERT_VERSION; # error A newer version of libixp is needed for this compilation. #endif #if IXP_API > IXP_MAXAPI -# warning This version of libixp has a newer API than this compilation requires. +# warning This version of libixp has a newer API than this compilation requests. #endif #if IXP_NEEDAPI < 127 +# undef uchar # undef ushort # undef ulong # undef vlong # undef uvlong +# define uchar _ixpuchar # define ushort _ixpushort # define ulong _ixpulong # define vlong _ixpvlong # define uvlong _ixpuvlong +typedef unsigned char uchar; typedef uint16_t ushort; typedef uint32_t ulong; typedef uint64_t uvlong; @@ -66,11 +72,8 @@ typedef uint64_t uvlong; typedef int64_t vlong; #endif -#undef uchar #undef uint -#define uchar _ixpuchar #define uint _ixpuint -typedef unsigned char uchar; typedef unsigned int uint; #ifdef KENC @@ -398,7 +401,7 @@ struct IxpFIO { struct IxpFRStat { IxpFHdr hdr; uint16_t nstat; - uchar* stat; + uint8_t* stat; }; struct IxpFTWStat { IxpFHdr hdr; @@ -456,7 +459,7 @@ struct IxpFcall { /* Deprecated */ ) STRUCT ( /* Rstat */ uint16_t nstat; - uchar *stat; + char *stat; ) STRUCT ( /* Twstat */ IxpStat st; @@ -739,12 +742,12 @@ int ixp_remove(IxpClient*, const char*); void ixp_unmount(IxpClient*); int ixp_vprint(IxpCFid*, const char*, va_list); long ixp_write(IxpCFid*, const void*, long); -IxpCFid* ixp_create(IxpClient*, const char*, uint perm, uchar mode); +IxpCFid* ixp_create(IxpClient*, const char*, uint perm, int8_t mode); IxpStat* ixp_fstat(IxpCFid*); IxpClient* ixp_mount(const char*); IxpClient* ixp_mountfd(int); IxpClient* ixp_nsmount(const char*); -IxpCFid* ixp_open(IxpClient*, const char*, uchar); +IxpCFid* ixp_open(IxpClient*, const char*, uint8_t); IxpStat* ixp_stat(IxpClient*, const char*); /* convert.c */ diff --git a/include/ixp_srvutil.h b/include/ixp_srvutil.h @@ -32,7 +32,7 @@ struct IxpPending { struct IxpDirtab { char* name; - uchar qtype; + uint8_t qtype; uint type; uint perm; uint flags; @@ -46,7 +46,7 @@ struct IxpFileId { uint index; IxpDirtab tab; uint nref; - uchar volatil; + char volatil; }; enum { @@ -55,9 +55,11 @@ enum { bool ixp_pending_clunk(Ixp9Req*); void ixp_pending_flush(Ixp9Req*); +int ixp_pending_print(IxpPending*, const char*, ...); void ixp_pending_pushfid(IxpPending*, IxpFid*); void ixp_pending_respond(Ixp9Req*); -void ixp_pending_write(IxpPending*, char*, long); +int ixp_pending_vprint(IxpPending*, const char*, va_list ap); +void ixp_pending_write(IxpPending*, const char*, long); IxpFileId* ixp_srv_clonefiles(IxpFileId*); void ixp_srv_data2cstring(Ixp9Req*); void ixp_srv_freefile(IxpFileId*); diff --git a/lib/libixp/convert.c b/lib/libixp/convert.c @@ -17,11 +17,11 @@ enum { static void ixp_puint(IxpMsg *msg, uint size, uint32_t *val) { - uchar *pos; + uint8_t *pos; int v; if(msg->pos + size <= msg->end) { - pos = (uchar*)msg->pos; + pos = (uint8_t*)msg->pos; switch(msg->mode) { case MsgPack: v = *val; @@ -74,16 +74,12 @@ ixp_puint(IxpMsg *msg, uint size, uint32_t *val) { * T<IxpMsg> */ void -ixp_pu32(IxpMsg *msg, uint32_t *val) { - ixp_puint(msg, SDWord, val); -} -void -ixp_pu8(IxpMsg *msg, uchar *val) { +ixp_pu8(IxpMsg *msg, uint8_t *val) { uint32_t v; v = *val; ixp_puint(msg, SByte, &v); - *val = (uchar)v; + *val = (uint8_t)v; } void ixp_pu16(IxpMsg *msg, uint16_t *val) { @@ -94,6 +90,10 @@ ixp_pu16(IxpMsg *msg, uint16_t *val) { *val = (uint16_t)v; } void +ixp_pu32(IxpMsg *msg, uint32_t *val) { + ixp_puint(msg, SDWord, val); +} +void ixp_pu64(IxpMsg *msg, uint64_t *val) { uint32_t vl, vb; diff --git a/lib/libixp/srv_util.c b/lib/libixp/srv_util.c @@ -239,6 +239,8 @@ ixp_srv_writectl(Ixp9Req *req, char* (*fn)(void*, IxpMsg*)) { /** * Function: ixp_pending_write + * Function: ixp_pending_print + * Function: ixp_pending_vprint * Function: ixp_pending_pushfid * Function: ixp_pending_clunk * Function: ixp_pending_flush @@ -263,6 +265,9 @@ ixp_srv_writectl(Ixp9Req *req, char* (*fn)(void*, IxpMsg*)) { * queued when ixp_pending_respond is called, it is written * immediately, otherwise the request is queued. * + * ixp_pending_print and ixp_pending_vprint call ixp_pending_write + * after formatting their arguments with V<ixp_vsmprint>. + * * The IxpPending data structure is opaque and should be * initialized zeroed before using these functions for the first * time. @@ -307,7 +312,7 @@ ixp_pending_respond(Ixp9Req *req) { } void -ixp_pending_write(IxpPending *pending, char *dat, long ndat) { +ixp_pending_write(IxpPending *pending, const char *dat, long ndat) { IxpRequestLink req_link; IxpQueue **qp, *queue; IxpPendingLink *pp; @@ -348,6 +353,29 @@ ixp_pending_write(IxpPending *pending, char *dat, long ndat) { ixp_pending_respond(rp->req); } +int +ixp_pending_vprint(IxpPending *pending, const char *fmt, va_list ap) { + char *dat; + int res; + + dat = ixp_vsmprint(fmt, ap); + res = strlen(dat); + ixp_pending_write(pending, dat, res); + free(dat); + return res; +} + +int +ixp_pending_print(IxpPending *pending, const char *fmt, ...) { + va_list ap; + int res; + + va_start(ap, fmt); + res = ixp_pending_vprint(pending, fmt, ap); + va_end(ap); + return res; +} + void ixp_pending_pushfid(IxpPending *pending, IxpFid *fid) { IxpPendingLink *pend_link;