/[zanavi_public1]/navit/navit/support/glib/fake.c
ZANavi

Contents of /navit/navit/support/glib/fake.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Oct 28 21:19:04 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 2762 byte(s)
import files
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 void
93 g_get_current_time (GTimeVal *result)
94 {
95 #ifndef G_OS_WIN32
96 struct timeval r;
97
98 g_return_if_fail (result != NULL);
99
100 /*this is required on alpha, there the timeval structs are int's
101 not longs and a cast only would fail horribly*/
102 gettimeofday (&r, NULL);
103 result->tv_sec = r.tv_sec;
104 result->tv_usec = r.tv_usec;
105 #else
106 FILETIME ft;
107 guint64 time64;
108
109 g_return_if_fail (result != NULL);
110
111 #if defined(HAVE_API_WIN32_CE)
112 GetCurrentFT(&ft);
113 #else
114 GetSystemTimeAsFileTime (&ft);
115 #endif
116 memmove (&time64, &ft, sizeof (FILETIME));
117
118 /* Convert from 100s of nanoseconds since 1601-01-01
119 * to Unix epoch. Yes, this is Y2038 unsafe.
120 */
121 time64 -= G_GINT64_CONSTANT (116444736000000000);
122 time64 /= 10;
123
124 result->tv_sec = time64 / 1000000;
125 result->tv_usec = time64 % 1000000;
126 #endif
127 }
128
129 // FIXME: should use real utf8-aware function
130 gchar * g_utf8_casefold(const gchar *s, gssize len)
131 {
132 return g_ascii_strdown(s,len);
133 }
134

   
Visit the ZANavi Wiki