2004-06-10 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mono / io-layer / misc.c
index 102798c7af54a7966e8393f65ab3abc61c61020c..9d2f427a2e1ca357800ea1475cd32cdfc32c94dd 100644 (file)
@@ -18,10 +18,22 @@ void _wapi_calc_timeout(struct timespec *timeout, guint32 ms)
 {
        struct timeval now;
        div_t divvy;
-               
-       divvy=div((int)ms, 1000);
+
        gettimeofday(&now, NULL);
+       divvy=div((now.tv_usec/1000)+ms, 1000);
                
        timeout->tv_sec=now.tv_sec+divvy.quot;
-       timeout->tv_nsec=(now.tv_usec+(divvy.rem*1000))*1000;
+       timeout->tv_nsec=divvy.rem*1000000;
+}
+
+/* This is used instead of g_renew when we need to keep unused
+ * elements NULL, because g_renew doesn't initialize the memory it
+ * returns.
+ */
+gpointer _wapi_g_renew0 (gpointer mem, gulong old_len, gulong new_len)
+{
+       gpointer new_mem=g_malloc0 (new_len);
+       memcpy (new_mem, mem, old_len);
+       g_free (mem);
+       return(new_mem);
 }