From 627ed4a556b987aba5452199ec6f7931dec944fe Mon Sep 17 00:00:00 2001 From: Karl Ramm Date: Tue, 25 Dec 2007 05:37:11 +0000 Subject: these should have been added when the branch was merged. *sigh* --- lib/ZMakeZcode.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/ZMakeZcode.c (limited to 'lib/ZMakeZcode.c') diff --git a/lib/ZMakeZcode.c b/lib/ZMakeZcode.c new file mode 100644 index 0000000..6229bef --- /dev/null +++ b/lib/ZMakeZcode.c @@ -0,0 +1,80 @@ +/* This file is part of the Project Athena Zephyr Notification System. + * It contains source for the ZMakeZcode function. + * + * Created by: Jeffrey Hutzelman + * + * $Id$ + * + * Copyright (c) 1987, 2002 by the Massachusetts Institute of Technology. + * For copying and distribution information, see the file + * "mit-copyright.h". + */ + +#include +#include + +#ifndef lint +static const char rcsid_ZMakeZcode_c[] = "$Id$"; +#endif + +Code_t ZMakeZcode32(ptr, len, val) + char *ptr; + int len; + unsigned long val; +{ + unsigned char buf[4]; + buf[0] = (val >> 24) & 0xff; + buf[1] = (val >> 16) & 0xff; + buf[2] = (val >> 8) & 0xff; + buf[3] = val & 0xff; + return ZMakeZcode(ptr, len, buf, 4); +} + +Code_t ZMakeZcode(ptr, len, field, num) + register char *ptr; + int len; + unsigned char *field; + int num; +{ + int i; + + /* + * This optimistic check lets us discover quickly if the buffer + * is not even large enough to hold the field without escapes. + * It also insures we'll have space for the leading 'Z' and the + * trailing NUL. Note that this does _not_ remove the need for + * checking length as we encode. + */ + if (len < num + 2) + return ZERR_FIELDLEN; + *ptr++ = 'Z'; + --len; + for (i=0;i