X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/410c8acf139e945dce28bbc0c8b17dcfd0815643..f87966dbaeaecb7e1abbc84f7137f5ce8de07a16:/servutil.c diff --git a/servutil.c b/servutil.c index 951df2d7..590327db 100644 --- a/servutil.c +++ b/servutil.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: servutil.c,v 1.1 2001/02/03 20:26:37 mdw Exp $ + * $Id: servutil.c,v 1.5 2004/04/08 01:36:17 mdw Exp $ * * Various handy server-only utilities * @@ -26,18 +26,14 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: servutil.c,v $ - * Revision 1.1 2001/02/03 20:26:37 mdw - * Initial checkin. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "tripe.h" +/*----- Global variables --------------------------------------------------*/ + +octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ]; + /*----- Main code ---------------------------------------------------------*/ /* --- @mpstr@ --- * @@ -47,14 +43,52 @@ * Returns: A pointer to the integer's textual representation. * * Use: Converts a multiprecision integer to a string. Corrupts - * @buf_o@. + * @buf_t@. */ const char *mpstr(mp *m) { - if (mp_writestring(m, (char *)buf_o, sizeof(buf_o), 10)) + if (mp_writestring(m, (char *)buf_t, sizeof(buf_t), 10)) return (""); - return ((const char *)buf_o); + return ((const char *)buf_t); +} + +/* --- @gestr@ --- * + * + * Arguments: @group *g@ = a group + * @ge *x@ = a group element + * + * Returns: A pointer to the element's textual representation. + * + * Use: Converts a group element to a string. Corrupts + * @buf_t@. + */ + +const char *gestr(group *g, ge *x) +{ + if (group_writestring(g, x, (char *)buf_t, sizeof(buf_t))) + return (""); + return ((const char *)buf_t); +} + +/* --- @timestr@ --- * + * + * Arguments: @time_t t@ = a time to convert + * + * Returns: A pointer to a textual representation of the time. + * + * Use: Converts a time to a textual representation. Corrupts + * @buf_t@. + */ + +const char *timestr(time_t t) +{ + struct tm *tm; + if (!t) + return ("NEVER"); + tm = localtime(&t); + strftime((char *)buf_t, sizeof(buf_t), "%Y-%m-%dT%H:%M:%S", tm); + return ((const char *)buf_t); } /*----- That's all, folks -------------------------------------------------*/