comparison srvrlib/ts2str.c @ 0:c7f6b056b673

First import of vendor version
author Peter Gervai <grin@grin.hu>
date Tue, 10 Mar 2009 13:49:58 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c7f6b056b673
1 /* Distributed Checksum Clearinghouse
2 *
3 * Copyright (c) 2008 by Rhyolite Software, LLC
4 *
5 * This agreement is not applicable to any entity which sells anti-spam
6 * solutions to others or provides an anti-spam solution as part of a
7 * security solution sold to other entities, or to a private network
8 * which employs the DCC or uses data provided by operation of the DCC
9 * but does not provide corresponding data to other users.
10 *
11 * Permission to use, copy, modify, and distribute this software without
12 * changes for any purpose with or without fee is hereby granted, provided
13 * that the above copyright notice and this permission notice appear in all
14 * copies and any distributed versions or copies are either unchanged
15 * or not called anything similar to "DCC" or "Distributed Checksum
16 * Clearinghouse".
17 *
18 * Parties not eligible to receive a license under this agreement can
19 * obtain a commercial license to use DCC by contacting Rhyolite Software
20 * at sales@rhyolite.com.
21 *
22 * A commercial license would be for Distributed Checksum and Reputation
23 * Clearinghouse software. That software includes additional features. This
24 * free license for Distributed ChecksumClearinghouse Software does not in any
25 * way grant permision to use Distributed Checksum and Reputation Clearinghouse
26 * software
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
29 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
30 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
31 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
32 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
33 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
34 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
35 * SOFTWARE.
36 *
37 * Rhyolite Software DCC 1.3.103-1.25 $Revision$
38 */
39
40 #include "srvr_defs.h"
41
42
43 /* not necessarily thread safe because DCC_GMTIME_R might be ancient */
44 char *
45 ts2str(char *ts_buf, u_int ts_buf_len, const DCC_TS *ts)
46 {
47 struct timeval tv;
48 time_t secs;
49 struct tm tm;
50 char time_buf[30];
51
52 dcc_ts2timeval(&tv, ts);
53 secs = tv.tv_sec; /* tv_sec is not always a time_t */
54 DCC_GMTIME_R(&secs, &tm);
55 strftime(time_buf, sizeof(time_buf), "%y/%m/%d %H:%M:%S", &tm);
56 snprintf(ts_buf, ts_buf_len, "%s.%06d",
57 time_buf, (int)tv.tv_usec);
58 return ts_buf;
59 }
60
61
62
63 /* this is not thread safe but good enough for error messages */
64 const char *
65 ts2str_err(const DCC_TS *ts)
66 {
67 static int bufno;
68 static struct {
69 char str[40];
70 } bufs[4];
71 char *s;
72
73 s = bufs[bufno].str;
74 bufno = (bufno+1) % DIM(bufs);
75
76 return ts2str(s, sizeof(bufs[0].str), ts);
77 }