summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-01-11 12:10:14 -0500
committerNick Mathewson <nickm@torproject.org>2012-01-11 12:10:14 -0500
commitf729e1e984896a9d6852768a8e5528932f668ac3 (patch)
treef6e1aa68ec9e5f6875a06224333b96b8f7938b2e /src/common
parentf37181620951d2e7a13f1363386563115d628761 (diff)
parentb5af456685b502462385b5f1b7f22f4374822fe1 (diff)
downloadtor-f729e1e984896a9d6852768a8e5528932f668ac3.tar.gz
tor-f729e1e984896a9d6852768a8e5528932f668ac3.zip
Merge branch 'feature3457-v4-nm-squashed'
Conflicts: src/or/rendclient.c
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c20
-rw-r--r--src/common/util.h3
2 files changed, 23 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 6d488d9963..22c816abcc 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1430,6 +1430,26 @@ format_iso_time(char *buf, time_t t)
strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm));
}
+/** As format_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid
+ * embedding an internal space. */
+void
+format_iso_time_nospace(char *buf, time_t t)
+{
+ format_iso_time(buf, t);
+ buf[10] = 'T';
+}
+
+/** As format_iso_time_nospace, but include microseconds in decimal
+ * fixed-point format. Requires that buf be at least ISO_TIME_USEC_LEN+1
+ * bytes long. */
+void
+format_iso_time_nospace_usec(char *buf, const struct timeval *tv)
+{
+ tor_assert(tv);
+ format_iso_time_nospace(buf, tv->tv_sec);
+ tor_snprintf(buf+ISO_TIME_LEN, 8, ".%06d", (int)tv->tv_usec);
+}
+
/** Given an ISO-formatted UTC time value (after the epoch) in <b>cp</b>,
* parse it and store its value in *<b>t</b>. Return 0 on success, -1 on
* failure. Ignore extraneous stuff in <b>cp</b> separated by whitespace from
diff --git a/src/common/util.h b/src/common/util.h
index 3a68f3993d..cbc56d0816 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -238,8 +238,11 @@ time_t tor_timegm(struct tm *tm);
void format_rfc1123_time(char *buf, time_t t);
int parse_rfc1123_time(const char *buf, time_t *t);
#define ISO_TIME_LEN 19
+#define ISO_TIME_USEC_LEN (ISO_TIME_LEN+7)
void format_local_iso_time(char *buf, time_t t);
void format_iso_time(char *buf, time_t t);
+void format_iso_time_nospace(char *buf, time_t t);
+void format_iso_time_nospace_usec(char *buf, const struct timeval *tv);
int parse_iso_time(const char *buf, time_t *t);
int parse_http_time(const char *buf, struct tm *tm);
int format_time_interval(char *out, size_t out_len, long interval);