From 2a79930d731c6d85df0fc46e869a4466dbf1d1fd Mon Sep 17 00:00:00 2001 From: "Robert S. French" Date: Fri, 12 Jun 1987 12:58:47 +0000 Subject: First working library - safe checkin --- lib/ZPeekIfNot.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/ZPeekIfNot.c (limited to 'lib/ZPeekIfNot.c') diff --git a/lib/ZPeekIfNot.c b/lib/ZPeekIfNot.c new file mode 100644 index 0000000..f52cdd6 --- /dev/null +++ b/lib/ZPeekIfNot.c @@ -0,0 +1,66 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It contains source for the ZPeekIfNotice function. + * + * Created by: Robert French + * + * $Source$ + * $Author$ + * + * Copyright (c) 1987 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ +/* $Header$ */ + +#include + +#include + +Code_t ZPeekIfNotice(buffer,buffer_len,notice,auth,predicate,args) + ZPacket_t buffer; + int buffer_len; + ZNotice_t *notice; + int *auth; + int (*predicate)(); + char *args; +{ + ZNotice_t tmpnotice; + int qcount,retval,tmpauth; + struct _Z_InputQ *qptr; + + if (__Q_Length) + retval = Z_ReadEnqueue(); + else + retval = Z_ReadWait(); + + if (retval != ZERR_NONE) + return (retval); + + qptr = __Q_Head; + qcount = __Q_Length; + + for (;;qcount--) { + if ((retval = ZParseNotice(qptr->packet,qptr->packet_len, + &tmpnotice,&tmpauth)) != ZERR_NONE) + return (retval); + if ((predicate)(&tmpnotice,args)) { + if (qptr->packet_len > buffer_len) + return (ZERR_PKTLEN); + bcopy(qptr->packet,buffer,qptr->packet_len); + if ((retval = ZParseNotice(buffer,qptr->packet_len, + notice,auth)) + != ZERR_NONE) + return (retval); + return (ZERR_NONE); + } + /* Grunch! */ + if (qcount == 1) { + if ((retval = Z_ReadWait()) != ZERR_NONE) + return (retval); + qcount++; + qptr = __Q_Tail; + } + else + qptr = qptr->next; + } +} -- cgit v1.2.3