1 |
#include "fake.h"
|
2 |
|
3 |
#include <stdlib.h> /* posix_memalign() */
|
4 |
#include <string.h>
|
5 |
#include <errno.h>
|
6 |
#include "gmem.h" /* gslice.h */
|
7 |
#include "gthreadprivate.h"
|
8 |
#include "glib.h"
|
9 |
#include "galias.h"
|
10 |
#ifdef HAVE_UNISTD_H
|
11 |
#include <unistd.h> /* sysconf() */
|
12 |
#endif
|
13 |
#ifdef G_OS_WIN32
|
14 |
#include <windows.h>
|
15 |
#include <process.h>
|
16 |
#endif
|
17 |
|
18 |
#include <stdio.h> /* fputs/fprintf */
|
19 |
|
20 |
char* g_convert (const char *in,
|
21 |
int len,
|
22 |
const char *to_codeset,
|
23 |
const char *from_codeset,
|
24 |
int *bytes_read,
|
25 |
int *bytes_written,
|
26 |
void **error)
|
27 |
{
|
28 |
return g_strdup(in);
|
29 |
}
|
30 |
|
31 |
|
32 |
#if USE_POSIX_THREADS
|
33 |
pthread_mutex_t* g_mutex_new_navit(void)
|
34 |
{
|
35 |
pthread_mutex_t *ret = malloc(sizeof(pthread_mutex_t));
|
36 |
pthread_mutex_init(ret, NULL);
|
37 |
return ret;
|
38 |
}
|
39 |
#else
|
40 |
#if HAVE_API_WIN32_BASE
|
41 |
CRITICAL_SECTION* g_mutex_new_navit(void)
|
42 |
{
|
43 |
CRITICAL_SECTION *ret = malloc(sizeof(CRITICAL_SECTION));
|
44 |
InitializeCriticalSection(ret);
|
45 |
return ret;
|
46 |
}
|
47 |
#endif
|
48 |
#endif
|
49 |
|
50 |
GPrivate
|
51 |
g_private_new_navit ()
|
52 |
{
|
53 |
#if HAVE_API_WIN32_BASE
|
54 |
int dwTlsIndex;
|
55 |
|
56 |
if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES)
|
57 |
printf("TlsAlloc failed");
|
58 |
printf("return dwTlsIndex = 0x%x\n",dwTlsIndex);
|
59 |
return dwTlsIndex;
|
60 |
#else
|
61 |
pthread_key_t key;
|
62 |
if (pthread_key_create(&key, NULL)) {
|
63 |
fprintf(stderr,"pthread_key_create failed\n");
|
64 |
}
|
65 |
return key;
|
66 |
#endif
|
67 |
}
|
68 |
|
69 |
/**
|
70 |
* g_get_current_time:
|
71 |
* @result: #GTimeVal structure in which to store current time.
|
72 |
*
|
73 |
* Equivalent to the UNIX gettimeofday() function, but portable.
|
74 |
**/
|
75 |
|
76 |
|
77 |
#ifndef HAVE_API_ANDROID
|
78 |
|
79 |
#ifdef HAVE_CYGWIN
|
80 |
// zoff for cygwin use this
|
81 |
// but should be left out on linux
|
82 |
// run "export C_FLAGS=-DHAVE_CYGWIN ; configure" on cygwin
|
83 |
struct timeval {
|
84 |
time_t tv_sec;
|
85 |
suseconds_t tv_usec;
|
86 |
};
|
87 |
// zoff for cygwin
|
88 |
#endif
|
89 |
|
90 |
#endif
|
91 |
|
92 |
|
93 |
|
94 |
void
|
95 |
g_get_current_time (GTimeVal *result)
|
96 |
{
|
97 |
#ifndef G_OS_WIN32
|
98 |
struct timeval r;
|
99 |
|
100 |
g_return_if_fail (result != NULL);
|
101 |
|
102 |
/*this is required on alpha, there the timeval structs are int's
|
103 |
not longs and a cast only would fail horribly*/
|
104 |
gettimeofday (&r, NULL);
|
105 |
result->tv_sec = r.tv_sec;
|
106 |
result->tv_usec = r.tv_usec;
|
107 |
#else
|
108 |
FILETIME ft;
|
109 |
guint64 time64;
|
110 |
|
111 |
g_return_if_fail (result != NULL);
|
112 |
|
113 |
#if defined(HAVE_API_WIN32_CE)
|
114 |
GetCurrentFT(&ft);
|
115 |
#else
|
116 |
GetSystemTimeAsFileTime (&ft);
|
117 |
#endif
|
118 |
memmove (&time64, &ft, sizeof (FILETIME));
|
119 |
|
120 |
/* Convert from 100s of nanoseconds since 1601-01-01
|
121 |
* to Unix epoch. Yes, this is Y2038 unsafe.
|
122 |
*/
|
123 |
time64 -= G_GINT64_CONSTANT (116444736000000000);
|
124 |
time64 /= 10;
|
125 |
|
126 |
result->tv_sec = time64 / 1000000;
|
127 |
result->tv_usec = time64 % 1000000;
|
128 |
#endif
|
129 |
}
|
130 |
|
131 |
// FIXME: should use real utf8-aware function
|
132 |
gchar * g_utf8_casefold(const gchar *s, gssize len)
|
133 |
{
|
134 |
return g_ascii_strdown(s,len);
|
135 |
}
|
136 |
|