Skip to contentSkip to conversation

supplement timegm function for Solaris in cutils.c

Qemu-devel Ben Taylor 2 participants 2 messages Nov 9, 2007 – Nov 10, 2007

lore
Share & tools
lore

Ben Taylor

author
#0 lore raw

Solaris doesn't have the timegm function, so I found a replacement and wedge it into cutils.c.

I found the supplement for timegm in the opensync repository at:
http://www.opensync.org/changeset/1769

cutils.c 2007-11-09 14:11:04.005353000 -0500 renamed from cutils.c 2007-09-16 17:07:49.000000000 -0400 +35 -0
@@ -81,3 +81,38 @@
         *ptr = p;
     return 1;
 }
+
+#ifdef __sun__
+/*
+ * On solaris no timegm function exists,
+ * we must implement it here
+ */
+time_t timegm(struct tm *t)
+{
+    time_t tl, tb;
+    struct tm *tg;
+
+    tl = mktime (t);
+     if (tl == -1)
+    {
+        t->tm_hour--;
+        tl = mktime (t);
+        if (tl == -1)
+            return -1; /* can't deal with output from strptime */
+        tl += 3600;
+    }
+    tg = gmtime (&tl);
+    tg->tm_isdst = 0;
+    tb = mktime (tg);
+    if (tb == -1)
+    {
+        tg->tm_hour--;
+        tb = mktime (tg);
+        if (tb == -1)
+            return -1; /* can't deal with output from gmtime */
+        tb += 3600;
+    }
+    return (tl - (tb - tl));
+}
+#endif
+
#1 lore raw

Windows does not seem to have this function either.
With your patch I was able to compile most of the targets from the current CVS tree (except arm), but at least i386-softmmu is broken.

It crashes immediately with the following error:

Starting program: c:\qemu-dist9/qemu.exe -L . -hda c:\qemu-img\wxp.q2 -boot c -localtime -m 512 -net nic,model=rtl8139 -net
tap,ifname=TAP0 -kernel-kqemu

Program received signal SIGSEGV, Segmentation fault. qcow_aio_read_cb (opaque=0x23dfcc70, ret=-22) at block-qcow2.c:840
840 acb->common.cb(acb->common.opaque, 0);

(gdb) q

Alex.

"Ben Taylor" <[email protected]> wrote in message news:20071109142635.5NICO.161491.root@eastrmwml12...

Quoted 52 lines

Solaris doesn't have the timegm function, so I found a replacement and wedge it into cutils.c.

I found the supplement for timegm in the opensync repository at:
http://www.opensync.org/changeset/1769

cutils.c 2007-11-09 14:11:04.005353000 -0500 renamed from cutils.c 2007-09-16 17:07:49.000000000 -0400 +35 -0
@@ -81,3 +81,38 @@
        *ptr = p;
    return 1;
 }
+
+#ifdef __sun__
+/*
+ * On solaris no timegm function exists,
+ * we must implement it here
+ */
+time_t timegm(struct tm *t)
+{
+    time_t tl, tb;
+    struct tm *tg;
+
+    tl = mktime (t);
+     if (tl == -1)
+    {
+        t->tm_hour--;
+        tl = mktime (t);
+        if (tl == -1)
+            return -1; /* can't deal with output from strptime */
+        tl += 3600;
+    }
+    tg = gmtime (&tl);
+    tg->tm_isdst = 0;
+    tb = mktime (tg);
+    if (tb == -1)
+    {
+        tg->tm_hour--;
+        tb = mktime (tg);
+        if (tb == -1)
+            return -1; /* can't deal with output from gmtime */
+        tb += 3600;
+    }
+    return (tl - (tb - tl));
+}
+#endif
+