The Assimilation Project  based on Assimilation version 1.1.7.1474836767
replacement_funs.c
Go to the documentation of this file.
1 
23 #include <projectcommon.h>
24 #include <string.h>
25 
26 #ifndef HAVE_G_GET_MONOTONIC_TIME
27 # include <time.h>
28 #endif
30 #ifndef HAVE_G_GET_REAL_TIME
31 
33 WINEXPORT gint64
35 {
36  GTimeVal tv;
37  guint64 ret;
38 
39  g_get_current_time(&tv);
40 
41  ret = (gint64)tv.tv_sec * (gint64)1000000UL;
42  ret += (gint64)tv.tv_usec;
43  return ret;
44 }
45 #endif
47 #ifndef HAVE_G_GET_MONOTONIC_TIME
48 #ifdef CLOCK_MONOTONIC
49 # define CLOCKARG CLOCK_MONOTONIC
50 #else
51 # define CLOCKARG CLOCK_REALTIME
52 #endif
53 
55 WINEXPORT gint64
57 {
58  struct timespec ts;
59  const gint64 million = 1000000UL;
60  const gint64 thousand = 1000UL;
61  if (clock_gettime(CLOCKARG, &ts) < 0) {
62  (void)clock_gettime(CLOCK_REALTIME, &ts); // Should never fail...
63  }
64  return ((gint64)ts.tv_sec * million) + (((gint64)ts.tv_nsec)/thousand);
65 }
66 #endif
68 #ifndef HAVE_G_SLIST_FREE_FULL
69 void
71 assim_slist_free_full(GSList* list, void (*datafree)(gpointer))
72 {
73  GSList* this = NULL;
74  GSList* next = NULL;
75  //fprintf(stderr, "Freeing GSList at %p\n", list);
76 
77  for (this=list; this; this=next) {
78  next=this->next;
79  //fprintf(stderr, "........Freeing GSList data at %p\n", this->data);
80  if (this->data) {
81  datafree(this->data);
82  //}else{
83  //fprintf(stderr, "........NO GSList data (NULL) at %p\n"
84  //, this->data);
85  }
86  //fprintf(stderr, "........Freeing GSList element at %p\n", this);
87  memset(this, 0, sizeof(*this));
88  g_slist_free_1(this);
89  }
90 }
91 #endif
93 #ifndef HAVE_G_GET_ENVIRON
94 // Need the glib version of this if we're on windows - it does character set conversion.
95 extern char **environ;
96 gchar **
98 {
99  guint envcount;
100  guint j;
101  gchar** result;
102 
103  for (envcount=0; environ[envcount]; ++envcount) {
104  /* Just count... */
105  }
106  result = (gchar **) malloc((envcount+1)*sizeof(gchar *));
107 
108  for (j=0; j < envcount; ++j) {
109  result[j] = g_strdup(environ[j]);
110  }
111  result[envcount] = NULL;
112  return result;
113 }
114 #endif
117 #ifndef g_queue_remove_boolean
118 gboolean
120 g_queue_remove_boolean(GQueue* queue, gconstpointer element)
121 {
122  GList* found_thing = g_queue_find(queue, element);
123  if (!found_thing) {
124  return FALSE;
125  }
126  g_queue_remove(queue, element);
127  return TRUE;
128 }
129 #endif
char ** environ
G_SLIST_FREE_FULL.
void assim_slist_free_full(GSList *list, void(*datafree)(gpointer))
HAVE_G_GET_MONOTONIC_TIME.
WINEXPORT gint64 g_get_real_time(void)
HAVE_G_GET_MONOTONIC_TIME.
#define WINEXPORT
Definition: projectcommon.h:45
WINEXPORT gint64 g_get_monotonic_time(void)
Local replacement for g_get_monotonic_time() - for old releases of glib.
Project common header file.
#define CLOCKARG
HAVE_G_GET_REAL_TIME.
gchar ** g_get_environ(void)
gboolean g_queue_remove_boolean(GQueue *queue, gconstpointer element)
HAVE_G_GET_ENVIRON.