Moved and integrated the exiting threads.
[mono.git] / mono / io-layer / misc.c
1 /*
2  * misc.c:  Miscellaneous internal support functions
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9
10 #include <config.h>
11 #include <glib.h>
12 #include <sys/time.h>
13 #include <stdlib.h>
14
15 #include "misc-private.h"
16
17 void _wapi_calc_timeout(struct timespec *timeout, guint32 ms)
18 {
19         struct timeval now;
20         div_t ms_divvy, overflow_divvy;
21         
22         gettimeofday (&now, NULL);
23
24         ms_divvy = div (ms, 1000);
25         overflow_divvy = div ((now.tv_usec / 1000) + ms_divvy.rem, 1000);
26                 
27         timeout->tv_sec = now.tv_sec + ms_divvy.quot + overflow_divvy.quot;
28         timeout->tv_nsec = overflow_divvy.rem * 1000000;
29 }
30
31 /* This is used instead of g_renew when we need to keep unused
32  * elements NULL, because g_renew doesn't initialize the memory it
33  * returns.
34  */
35 gpointer _wapi_g_renew0 (gpointer mem, gulong old_len, gulong new_len)
36 {
37         gpointer new_mem=g_malloc0 (new_len);
38         memcpy (new_mem, mem, old_len);
39         g_free (mem);
40         return(new_mem);
41 }