#include <glib.h>
#include <ctype.h>
+#include <stdlib.h>
#include <stdarg.h>
+#include <time.h>
#include "util.h"
void
return ret;
}
+static void
+hash_callback_key(gpointer key, gpointer value, gpointer user_data)
+{
+ GList **l=user_data;
+ *l=g_list_prepend(*l, key);
+}
+
+GList *
+g_hash_to_list_keys(GHashTable *h)
+{
+ GList *ret=NULL;
+ g_hash_table_foreach(h, hash_callback_key, &ret);
+
+ return ret;
+}
+
gchar *
g_strconcat_printf(gchar *buffer, gchar *fmt, ...)
{
#if defined(_WIN32) || defined(__CEGCC__)
#include <windows.h>
+#endif
+
+#if defined(_WIN32) || defined(__CEGCC__) || defined (__APPLE__)
#include <stdio.h>
char *stristr(const char *String, const char *Pattern)
{
}
#endif
#endif
+
+unsigned int
+iso8601_to_secs(char *iso8601)
+{
+ int a,b,d,val[6],i=0;
+ char *start=iso8601,*pos=iso8601;
+ while (*pos && i < 6) {
+ if (*pos < '0' || *pos > '9') {
+ val[i++]=atoi(start);
+ pos++;
+ start=pos;
+ }
+ pos++;
+ }
+
+ a=val[0]/100;
+ b=2-a+a/4;
+
+ if (val[1] < 2) {
+ val[0]--;
+ val[1]+=12;
+ }
+
+ d=1461*(val[0]+4716)/4+306001*(val[1]+1)/10000+val[2]+b-2442112;
+
+ return ((d*24+val[3])*60+val[4])*60+val[5];
+}
+
+char *
+current_to_iso8601(void)
+{
+ char buffer[32];
+ char *timep=NULL;
+#ifdef HAVE_GLIB
+ GTimeVal time;
+ g_get_current_time(&time);
+ timep = g_time_val_to_iso8601(&time);
+#else
+#ifdef HAVE_API_WIN32_BASE
+ SYSTEMTIME ST;
+ GetSystemTime(&ST);
+ timep=g_strdup_printf("%d-%02d-%02dT%02d:%02d:%02dZ",ST.wYear,ST.wMonth,ST.wDay,ST.wHour,ST.wMinute,ST.wSecond);
+#else
+ time_t tnow;
+ struct tm *tm;
+ tnow = time(0);
+ tm = gmtime(&tnow);
+ if (tm) {
+ strftime(buffer, sizeof(buffer), "%Y-%m-%dT%TZ", tm);
+ timep=g_strdup(buffer);
+ }
+#endif
+#endif
+ return timep;
+}