1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*********************************************************
* Copyright (C) 2011-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
/**
* @file VGAuthUtil.h --
*
* Convenient utility macros and declarations
*/
#ifndef _VGAUTH_UTIL_H_
#define _VGAUTH_UTIL_H_
#include <glib.h>
/* For unit testing the code */
void HangThread(const char *func, const char *file, unsigned line);
#define HANG_THREAD() do { \
HangThread(__FUNCTION__, __FILE__, __LINE__); \
} while (0)
#ifdef _WIN32
gunichar2 *Convert_Utf8ToUtf16(const char *func, const char *file,
unsigned line, const gchar *str);
#define CHK_UTF8_TO_UTF16(utf16Out, utf8In, onErrStmt) do { \
utf16Out = Convert_Utf8ToUtf16(__FUNCTION__, __FILE__, __LINE__, \
utf8In); \
if (!utf16Out) { \
onErrStmt; \
} \
} while(0)
gchar *Convert_Utf16ToUtf8(const char *func, const char *file,
unsigned line, const gunichar2 *str);
#define CHK_UTF16_TO_UTF8(utf8Out, utf16In, onErrStmt) do { \
utf8Out = Convert_Utf16ToUtf8(__FUNCTION__, __FILE__, __LINE__, \
utf16In); \
if (!utf8Out) { \
onErrStmt; \
} \
} while(0)
gboolean Convert_TextToUnsignedInt32(const char *func, const char *file,
unsigned line, const char *repr,
unsigned int *result);
#define CHK_TEXT_TO_UINT32(uint32Out, textIn, onErrStmt) do { \
gboolean ok = Convert_TextToUnsignedInt32(__FUNCTION__, __FILE__, \
__LINE__, textIn, \
&uint32Out); \
if (!ok) { \
onErrStmt; \
} \
} while(0)
gboolean Check_Is32bitNumber(size_t number);
gchar *Convert_UnsignedInt32ToText(unsigned int number);
#endif // #ifdef _WIN32
gboolean Util_CheckExpiration(const GTimeVal *start, unsigned int duration);
/*
* Converts a utf8 path into the local encoding. No-op on Windows.
*/
#ifdef _WIN32
#define GET_FILENAME_LOCAL(path, err) (gchar *) path
#define RELEASE_FILENAME_LOCAL(path) (void) (path)
#define DIRSEPS "\\"
#else
#define GET_FILENAME_LOCAL(path, err) g_filename_from_utf8((path), -1, NULL, NULL, (err))
#define RELEASE_FILENAME_LOCAL(path) g_free(path)
#define DIRSEPS "/"
#endif
/*
* Macro literal fun.
*
* Given:
*
* #define FOO foo
*
* Then:
*
* MAKESTR(FOO) becomes "FOO"
* XTR(FOO) becomes "foo"
*/
#ifndef MAKESTR
#define MAKESTR(x) #x
#define XSTR(x) MAKESTR(x)
#endif
void Util_Assert(const char *cond, const char *file, int lineNum);
#endif
|