chiark / gitweb /
Use new spare buffer for building MP textual representations. Add a
authormdw <mdw>
Fri, 16 Feb 2001 21:41:06 +0000 (21:41 +0000)
committermdw <mdw>
Fri, 16 Feb 2001 21:41:06 +0000 (21:41 +0000)
function for making human-readable time strings.

servutil.c

index 951df2d7e63d3e411adf20e7c2f905a36bb59b15..2c5f3d8356dc7bebcf858a6be00b550a79338a40 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
 /* -*-c-*-
  *
- * $Id: servutil.c,v 1.1 2001/02/03 20:26:37 mdw Exp $
+ * $Id: servutil.c,v 1.2 2001/02/16 21:41:06 mdw Exp $
  *
  * Various handy server-only utilities
  *
  *
  * Various handy server-only utilities
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: servutil.c,v $
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: servutil.c,v $
+ * Revision 1.2  2001/02/16 21:41:06  mdw
+ * Use new spare buffer for building MP textual representations.  Add a
+ * function for making human-readable time strings.
+ *
  * Revision 1.1  2001/02/03 20:26:37  mdw
  * Initial checkin.
  *
  * Revision 1.1  2001/02/03 20:26:37  mdw
  * Initial checkin.
  *
  * Returns:    A pointer to the integer's textual representation.
  *
  * Use:                Converts a multiprecision integer to a string.  Corrupts
  * 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)
 {
  */
 
 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 ("<failed>");
     return ("<failed>");
-  return ((const char *)buf_o);
+  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 -------------------------------------------------*/
 }
 
 /*----- That's all, folks -------------------------------------------------*/