Skip to content
Browse files

2007-04-27 Jonathan Chambers <joncham@gmail.com>

	
	Combined patch from Michael Jerris <mike@jerris.com> and me.
	* winconfig.h: Config file for msvc builds.
	* configure.ac: Add AC_CHECK_HEADERS for getopt.h,  sys/time.h,
	sys/wait.h, and pwd.h.
	
	* src/gspawn.c: Include config.h and use HAVE_* macros.
	* src/eglib-config.h.in: Add inclusion guards.
	* src/ghashtable.c: Fix warnings.
	* src/gmisc.c: Windows implementation of g_getenv, g_setenv,
	and g_unsetenv.
	* src/gpath.c: Include config.h and use HAVE_* macros.
	* src/gmarkup.c: Fix warnings.
	* src/gptrarray.c: Fix warnings.
	* src/gstr.c: Fix warnings and use HAVE_* macros.
	* src/glib.h: Move macros to eglib-config.h and include it.
	* src/gdate.c: Implement g_get_current_time on windows.
	* src/gpattern.c: Fix warnings.
	* src/gdir.c: Implement g_dir on windows.
	* src/gfile.c: Implement mkstemp and g_file_test on windows.
	* src/gtimer.c: Implement g_timer on windows.
	* src/gmodule.c: Fix warnings.
	* src/gunicode.c: Fix warnings.
	* src/gutf8.c: Fix warnings.
	
	* test/ptrarray.c: Fix warnings.
	* test/string.c: Fix warnings.
	* test/list.c: Fix warnings.
	* test/pattern.c: Use HAVE_* macros.
	* test/dir.c: Use HAVE_* macros.
	* test/file.c: Use HAVE_* macros and use system specific files for tests.
	* test/test.c: Fix warnings and use HAVE_* macros.
	* test/timer.c: Use HAVE_* macros.
	* test/string-util.c: Fix warnings.
	* test/test.h: Supress warnings on msvc.
	* test/module.c: Use HAVE_* macros.
	* test/utf8.c: Fix warnings.
	* test/spawn.c: Use HAVE_* macros.
	* test/driver.c: Fix warnings and use HAVE_* macros.
	* test/path.c: Use HAVE_* macros and use system specific files for tests.
	* test/sizes.c: Fix warnings.

2007-04-27  Jonathan Chambers <joncham@gmail.com>
	
	Combined patch from Michael Jerris <mike@jerris.com> and me.
	* getopt.c: Added public domain implementation for Windows.
	* getopt.h: Added public domain implementation for Windows.
	* getopt_long.c: Added public domain implementation for Windows.
	* test_eglib.vcproj: Update project.
	* eglib.vcproj: Update project. Add pre-build step to copy
	winconfig.h to config.h for msvc build.


svn path=/trunk/mono/; revision=76406
  • Loading branch information...
1 parent 43b0dac commit 10f6ce36d07c00789834d399ccf82a97f5972d5b @joncham joncham committed Apr 27, 2007
View
44 eglib/ChangeLog
@@ -1,3 +1,46 @@
+2007-04-27 Jonathan Chambers <joncham@gmail.com>
+
+ Combined patch from Michael Jerris <mike@jerris.com> and me.
+ * winconfig.h: Config file for msvc builds.
+ * configure.ac: Add AC_CHECK_HEADERS for getopt.h, sys/time.h,
+ sys/wait.h, and pwd.h.
+
+ * src/gspawn.c: Include config.h and use HAVE_* macros.
+ * src/eglib-config.h.in: Add inclusion guards.
+ * src/ghashtable.c: Fix warnings.
+ * src/gmisc.c: Windows implementation of g_getenv, g_setenv,
+ and g_unsetenv.
+ * src/gpath.c: Include config.h and use HAVE_* macros.
+ * src/gmarkup.c: Fix warnings.
+ * src/gptrarray.c: Fix warnings.
+ * src/gstr.c: Fix warnings and use HAVE_* macros.
+ * src/glib.h: Move macros to eglib-config.h and include it.
+ * src/gdate.c: Implement g_get_current_time on windows.
+ * src/gpattern.c: Fix warnings.
+ * src/gdir.c: Implement g_dir on windows.
+ * src/gfile.c: Implement mkstemp and g_file_test on windows.
+ * src/gtimer.c: Implement g_timer on windows.
+ * src/gmodule.c: Fix warnings.
+ * src/gunicode.c: Fix warnings.
+ * src/gutf8.c: Fix warnings.
+
+ * test/ptrarray.c: Fix warnings.
+ * test/string.c: Fix warnings.
+ * test/list.c: Fix warnings.
+ * test/pattern.c: Use HAVE_* macros.
+ * test/dir.c: Use HAVE_* macros.
+ * test/file.c: Use HAVE_* macros and use system specific files for tests.
+ * test/test.c: Fix warnings and use HAVE_* macros.
+ * test/timer.c: Use HAVE_* macros.
+ * test/string-util.c: Fix warnings.
+ * test/test.h: Supress warnings on msvc.
+ * test/module.c: Use HAVE_* macros.
+ * test/utf8.c: Fix warnings.
+ * test/spawn.c: Use HAVE_* macros.
+ * test/driver.c: Fix warnings and use HAVE_* macros.
+ * test/path.c: Use HAVE_* macros and use system specific files for tests.
+ * test/sizes.c: Fix warnings.
+
2007-04-24 Jonathan Chambers <joncham@gmail.com>
Patch from Michael Jerris <mike@jerris.com>
@@ -16,7 +59,6 @@
* src/gmodule.c: Start msvc build.
* src/gunicode.c: Start msvc build.
-
2007-01-27 Robert Jordan <robertj@gmx.net>
* test/Makefile.am: Add linker option to be able to
View
2 eglib/configure.ac
@@ -50,6 +50,8 @@ AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(void *)
AC_CHECK_FUNCS(strlcpy)
+AC_CHECK_HEADERS(getopt.h sys/time.h sys/wait.h pwd.h)
+
if test $ac_cv_sizeof_void_p != $ac_cv_sizeof_int; then
GPOINTER_TO_INT="((gint)(long) (ptr))"
GPOINTER_TO_UINT="((guint)(long) (ptr))"
View
5 eglib/src/eglib-config.h.in
@@ -1,3 +1,6 @@
+#ifndef __EGLIB_CONFIG_H
+#define __EGLIB_CONFIG_H
+
/*
* System-dependent settings
*/
@@ -21,3 +24,5 @@ typedef signed @GSIZE@ gssize;
#define G_GSIZE_FORMAT @GSIZE_FORMAT@
#define G_GUINT64_FORMAT @G_GUINT64_FORMAT@
+
+#endif
View
12 eglib/src/gdate.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <glib.h>
-#ifdef _MSC_VER
+#ifdef G_OS_WIN32
#include <winsock2.h>
#else
#include <sys/time.h>
@@ -37,11 +37,19 @@
void
g_get_current_time (GTimeVal *result)
{
+#ifdef G_OS_WIN32
+ long int l = GetTickCount();
+
+ g_return_if_fail (result != NULL);
+
+ result->tv_sec = l / 1000;
+ result->tv_usec = (l % 1000) * 1000;
+#else
struct timeval tv;
g_return_if_fail (result != NULL);
gettimeofday (&tv, NULL);
result->tv_sec = tv.tv_sec;
result->tv_usec = tv.tv_usec;
+#endif
}
-
View
99 eglib/src/gdir.c
@@ -34,12 +34,19 @@
#ifndef _MSC_VER
#include <unistd.h>
#include <dirent.h>
+#else
+#include <io.h>
+#endif
+
+#ifdef G_OS_WIN32
+#include <winsock2.h>
#endif
struct _GDir {
#ifdef G_OS_WIN32
- /* FIXME */
- int dir;
+ HANDLE handle;
+ gchar* current;
+ gchar* next;
#else
DIR *dir;
#endif
@@ -49,7 +56,54 @@ GDir *
g_dir_open (const gchar *path, guint flags, GError **error)
{
#ifdef G_OS_WIN32
- return NULL;
+ GDir *dir;
+ gunichar2* path_utf16;
+ gunichar2* path_utf16_search;
+ WIN32_FIND_DATA find_data;
+
+ g_return_val_if_fail (path != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ dir = g_new0 (GDir, 1);
+
+ path_utf16 = u8to16 (path);
+
+ dir->handle = FindFirstFile (path_utf16, &find_data);
+ if (dir->handle == INVALID_HANDLE_VALUE) {
+ if (error) {
+ gint err = errno;
+ *error = g_error_new (G_LOG_DOMAIN, g_file_error_from_errno (err), strerror (err));
+ }
+ g_free (dir);
+ g_free (path_utf16);
+ return NULL;
+ }
+
+ /* now get files */
+ FindClose (dir->handle);
+ path_utf16_search = g_malloc ((wcslen(path_utf16) + 3)*sizeof(gunichar2));
+ wcscpy (path_utf16_search, path_utf16);
+ wcscat (path_utf16_search, L"\\*");
+
+ dir->handle = FindFirstFile (path_utf16_search, &find_data);
+ g_free (path_utf16_search);
+
+ while ((wcscmp (find_data.cFileName, L".") == 0) || (wcscmp (find_data.cFileName, L"..") == 0)) {
+ if (!FindNextFile (dir->handle, &find_data)) {
+ if (error) {
+ gint err = errno;
+ *error = g_error_new (G_LOG_DOMAIN, g_file_error_from_errno (err), strerror (err));
+ }
+ g_free (dir);
+ g_free (path_utf16);
+ return NULL;
+ }
+ }
+
+ dir->current = NULL;
+ dir->next = u16to8 (find_data.cFileName);
+
+ g_free (path_utf16);
+ return dir;
#else
GDir *dir;
@@ -75,7 +129,30 @@ const gchar *
g_dir_read_name (GDir *dir)
{
#ifdef G_OS_WIN32
- return NULL;
+ WIN32_FIND_DATA find_data;
+
+ g_return_val_if_fail (dir != NULL && dir->handle != 0, NULL);
+
+ if (dir->current)
+ g_free (dir->current);
+ dir->current = NULL;
+
+ dir->current = dir->next;
+
+ if (!dir->current)
+ return NULL;
+
+ dir->next = NULL;
+
+ do {
+ if (!FindNextFile (dir->handle, &find_data)) {
+ dir->next = NULL;
+ return dir->current;
+ }
+ } while ((wcscmp (find_data.cFileName, L".") == 0) || (wcscmp (find_data.cFileName, L"..") == 0));
+
+ dir->next = u16to8 (find_data.cFileName);
+ return dir->current;
#else
struct dirent *entry;
@@ -104,11 +181,23 @@ void
g_dir_close (GDir *dir)
{
#ifdef G_OS_WIN32
+ g_return_if_fail (dir != NULL && dir->handle != 0);
+
+ if (dir->current)
+ g_free (dir->current);
+ dir->current = NULL;
+ if (dir->next)
+ g_free (dir->next);
+ dir->next = NULL;
+ FindClose (dir->handle);
+ dir->handle = 0;
+ g_free (dir);
#else
- g_return_if_fail (dir != NULL && dir->dir != NULL);
+ g_return_if_fail (dir != NULL && dir->dir != 0);
closedir (dir->dir);
dir->dir = NULL;
g_free (dir);
#endif
}
+
View
88 eglib/src/gfile.c
@@ -25,17 +25,23 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <config.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#ifdef _MSC_VER
+
+#ifdef G_OS_WIN32
#include <io.h>
#define open _open
-#else
+#define S_ISREG(x) ((x & _S_IFMT) == _S_IFREG)
+#define S_ISDIR(x) ((x & _S_IFMT) == _S_IFDIR)
+#endif
+
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -158,13 +164,35 @@ g_file_get_contents (const gchar *filename, gchar **contents, gsize *length, GEr
return TRUE;
}
+#ifdef _MSC_VER
+int mkstemp (char *tmp_template)
+{
+ int fd;
+ gunichar2* utf16_template;
+
+ utf16_template = u8to16 (tmp_template);
+
+ fd = -1;
+ utf16_template = _wmktemp( utf16_template);
+ if (utf16_template && *utf16_template) {
+ /* FIXME: _O_TEMPORARY causes file to disappear on close causing a test to fail */
+ fd = _wopen( utf16_template, _O_BINARY | _O_CREAT /*| _O_TEMPORARY*/ | _O_EXCL, _S_IREAD | _S_IWRITE);
+ }
+
+ sprintf (tmp_template + strlen (tmp_template) - 6, "%S", utf16_template + wcslen (utf16_template) - 6);
+
+ g_free (utf16_template);
+ return fd;
+}
+#endif
+
gint
g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error)
{
const static gchar *default_tmpl = ".XXXXXX";
gchar *t;
gint fd;
- gint len;
+ size_t len;
g_return_val_if_fail (error == NULL || *error == NULL, -1);
@@ -187,7 +215,9 @@ g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error)
}
t = g_build_filename (g_get_tmp_dir (), tmpl, NULL);
+
fd = mkstemp (t);
+
if (fd == -1) {
if (error) {
int err = errno;
@@ -205,18 +235,63 @@ g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error)
return fd;
}
+#ifdef _MSC_VER
+#pragma warning(disable:4701)
+#endif
+
gboolean
g_file_test (const gchar *filename, GFileTest test)
{
+#ifdef G_OS_WIN32
+ struct _stat64 stat;
+ int ret = 0;
+ gunichar2* utf16_filename = NULL;
+
+ if (filename == NULL || test == 0)
+ return FALSE;
+
+ utf16_filename = u8to16 (filename);
+ ret = _wstati64 (utf16_filename, &stat);
+ g_free (utf16_filename);
+
+ if ((test & G_FILE_TEST_EXISTS) != 0) {
+ if (ret == 0)
+ return TRUE;
+ }
+
+ if (ret != 0)
+ return FALSE;
+
+ if ((test & G_FILE_TEST_IS_EXECUTABLE) != 0) {
+ if (stat.st_mode & _S_IEXEC)
+ return TRUE;
+ }
+
+ if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
+ if (stat.st_mode & _S_IFREG)
+ return TRUE;
+ }
+
+ if ((test & G_FILE_TEST_IS_DIR) != 0) {
+ if (stat.st_mode & _S_IFDIR)
+ return TRUE;
+ }
+
+ /* make this last in case it is OR'd with something else */
+ if ((test & G_FILE_TEST_IS_SYMLINK) != 0) {
+ return FALSE;
+ }
+
+ return FALSE;
+#else
struct stat st;
gboolean have_stat;
if (filename == NULL || test == 0)
return FALSE;
have_stat = FALSE;
-#ifdef G_OS_WIN32
-#else
+
if ((test & G_FILE_TEST_EXISTS) != 0) {
if (access (filename, F_OK) == 0)
return TRUE;
@@ -231,7 +306,6 @@ g_file_test (const gchar *filename, GFileTest test)
if (have_stat && S_ISLNK (st.st_mode))
return TRUE;
}
-#endif
if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
if (!have_stat)
@@ -246,5 +320,7 @@ g_file_test (const gchar *filename, GFileTest test)
return TRUE;
}
return FALSE;
+#endif
}
+
View
2 eglib/src/ghashtable.c
@@ -51,7 +51,7 @@ struct _GHashTable {
GDestroyNotify value_destroy_func, key_destroy_func;
};
-static const int prime_tbl[] = {
+static const guint prime_tbl[] = {
11, 19, 37, 73, 109, 163, 251, 367, 557, 823, 1237,
1861, 2777, 4177, 6247, 9371, 14057, 21089, 31627,
47431, 71143, 106721, 160073, 240101, 360163,
View
76 eglib/src/glib.h
@@ -7,16 +7,21 @@
#include <stdio.h>
#include <stddef.h>
#include <ctype.h>
-#ifndef _MSC_VER
+
+#ifdef _MSC_VER
+#pragma include_alias(<eglib-config.h>, <eglib-config.hw>)
+#else
#include <stdint.h>
-#include <eglib-config.h>
#endif
+#include <eglib-config.h>
+
#ifndef offsetof
# define offsetof(s_name,n_name) (size_t)(char *)&(((s_name*)0)->m_name)
#endif
#define __EGLIB_X11 1
+
/*
* Basic data types
*/
@@ -44,51 +49,6 @@ typedef unsigned __int64 guint64;
typedef float gfloat;
typedef double gdouble;
typedef unsigned __int16 gunichar2;
-/*
- * System-dependent settings
- */
-/*
-#define G_GNUC_PRETTY_FUNCTION @GNUC_PRETTY@
-#define G_GNUC_UNUSED @GNUC_UNUSED@
-#define G_BYTE_ORDER @ORDER@
-#define G_GNUC_NORETURN @GNUC_NORETURN@
-#define G_BREAKPOINT() @BREAKPOINT@
-#define G_OS_@OS@
-#define GPOINTER_TO_INT(ptr) @GPOINTER_TO_INT@
-#define GPOINTER_TO_UINT(ptr) @GPOINTER_TO_UINT@
-#define GINT_TO_POINTER(v) @GINT_TO_POINTER@
-#define GUINT_TO_POINTER(v) @GUINT_TO_POINTER@
-*/
-typedef uintptr_t gsize;
-typedef intptr_t gssize;
-typedef int pid_t;
-
-#define G_DIR_SEPARATOR '\\'
-#define G_DIR_SEPARATOR_S "\\"
-#define G_SEARCHPATH_SEPARATOR_S ";"
-#define G_SEARCHPATH_SEPARATOR ';'
-#define G_GSIZE_FORMAT "d"
-#define G_GUINT64_FORMAT "d"
-
-#define INT32_MAX 2147483647
-#define INT32_MIN (~ INT32_MAX)
-#define INT64_MAX 9223372036854775807i64
-#define INT64_MIN (~INT64_MAX)
-
-#define STDOUT_FILENO stdout
-#define STDERR_FILENO stderr
-
-/* FIXME: what should this be ?*/
-#define X_OK 1
-#define WNOHANG 1
-#define F_SETFD 1
-#define FD_CLOEXEC 1
-
-#undef inline
-#define inline __inline
-
-#define G_OS_WIN32 1
-
#else
/* Types defined in terms of the stdint.h */
typedef int8_t gint8;
@@ -103,6 +63,7 @@ typedef float gfloat;
typedef double gdouble;
typedef uint16_t gunichar2;
#endif
+
/*
* Macros
*/
@@ -273,11 +234,7 @@ gint g_snprintf (gchar *string, gulong n, gchar const *format, ..
#define g_vsnprintf vsnprintf
#define g_vasprintf vasprintf
-#ifdef HAVE_STRLCPY
-#define g_strlcpy strlcpy
-#else
gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
-#endif
gchar *g_ascii_strdown (const gchar *str, gssize len);
gint g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n);
@@ -288,10 +245,18 @@ gint g_ascii_xdigit_value (gchar c);
#define g_ascii_isxdigit(c) (isxdigit (c) != 0)
/* FIXME: g_strcasecmp supports utf8 unicode stuff */
+#ifdef _MSC_VER
+#define g_strcasecmp stricmp
+#define g_ascii_strcasecmp stricmp
+#define g_strncasecmp strnicmp
+#define g_strstrip(a) g_strchug (g_strchomp (a))
+#else
#define g_strcasecmp strcasecmp
#define g_ascii_strcasecmp strcasecmp
#define g_strncasecmp strncasecmp
#define g_strstrip(a) g_strchug (g_strchomp (a))
+#endif
+
#define G_STR_DELIMITERS "_-|> <."
@@ -559,6 +524,14 @@ typedef enum {
gunichar2 *g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_written, GError **error);
gchar *g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *items_written, GError **error);
+#define u8to16(str) g_utf8_to_utf16(str, (glong)strlen(str), NULL, NULL, NULL)
+
+#ifdef G_OS_WIN32
+#define u16to8(str) g_utf16_to_utf8(str, (glong)wcslen(str), NULL, NULL, NULL)
+#else
+#define u16to8(str) g_utf16_to_utf8(str, (glong)strlen(str), NULL, NULL, NULL)
+#endif
+
/*
* Path
*/
@@ -797,3 +770,4 @@ gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **
#endif
+
View
6 eglib/src/gmarkup.c
@@ -122,7 +122,7 @@ parse_value (const char *p, const char *end, char **value, GError **error)
;
if (p == end)
return end;
- l = p - start;
+ l = (int)(p - start);
p++;
*value = malloc (l + 1);
if (*value == NULL)
@@ -143,7 +143,7 @@ parse_name (const char *p, const char *end, char **value)
if (p == end)
return end;
- l = p - start;
+ l = (int)(p - start);
*value = malloc (l + 1);
if (*value == NULL)
return end;
@@ -311,7 +311,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
set_error ("%s", "Unfinished sequence");
goto fail;
}
- l = element_end - element_start;
+ l = (int)(element_end - element_start);
ename = malloc (l + 1);
if (ename == NULL)
goto fail;
View
45 eglib/src/gmisc.c
@@ -29,21 +29,66 @@
#include <stdlib.h>
#include <glib.h>
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
const gchar *
g_getenv(const gchar *variable)
{
+#ifdef G_OS_WIN32
+ gunichar2 *var, *buffer;
+ gchar* val = NULL;
+ gint32 buffer_size = 1024;
+ gint32 retval;
+ var = u8to16(variable);
+ buffer = g_malloc(buffer_size*sizeof(gunichar2));
+ retval = GetEnvironmentVariable (var, buffer, buffer_size);
+ if (retval != 0) {
+ if (retval > buffer_size) {
+ g_free (buffer);
+ buffer_size = retval;
+ buffer = g_malloc(buffer_size*sizeof(gunichar2));
+ retval = GetEnvironmentVariable (var, buffer, buffer_size);
+ }
+ val = u16to8 (buffer);
+ }
+ g_free(var);
+ g_free(buffer);
+ return val;
+#else
return getenv(variable);
+#endif
}
gboolean
g_setenv(const gchar *variable, const gchar *value, gboolean overwrite)
{
+#ifdef G_OS_WIN32
+ gunichar2 *var, *val;
+ gboolean result;
+ var = u8to16(variable);
+ val = u8to16(value);
+ result = (SetEnvironmentVariable(var, val) != 0) ? TRUE : FALSE;
+ g_free(var);
+ g_free(val);
+ return result;
+#else
return setenv(variable, value, overwrite) == 0;
+#endif
}
void
g_unsetenv(const gchar *variable)
{
+#ifdef G_OS_WIN32
+ gunichar2 *var;
+ var = u8to16(variable);
+ SetEnvironmentVariable(var, TEXT(""));
+ g_free(var);
+#else
unsetenv(variable);
+#endif
}
+
View
13 eglib/src/gmodule.c
@@ -118,8 +118,11 @@ g_module_open (const gchar *file, GModuleFlags flags)
return NULL;
if (file != NULL) {
+ gunichar2 *file16;
+ file16 = u8to16(file);
module->main_module = FALSE;
- module->handle = LoadLibrary (file);
+ module->handle = LoadLibrary (file16);
+ g_free(file16);
if (!module->handle) {
g_free (module);
return NULL;
@@ -169,7 +172,7 @@ w32_find_symbol (const gchar *symbol_name)
}
for (i = 0; i < needed / sizeof (HANDLE); i++) {
- gpointer proc = GetProcAddress (modules [i], symbol_name);
+ gpointer proc = (gpointer)(intptr_t)GetProcAddress (modules [i], symbol_name);
if (proc != NULL) {
g_free (modules);
return proc;
@@ -187,14 +190,14 @@ g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol)
return FALSE;
if (module->main_module) {
- *symbol = GetProcAddress (module->handle, symbol_name);
+ *symbol = (gpointer)(intptr_t)GetProcAddress (module->handle, symbol_name);
if (*symbol != NULL)
return TRUE;
*symbol = w32_find_symbol (symbol_name);
return *symbol != NULL;
} else {
- *symbol = GetProcAddress (module->handle, symbol_name);
+ *symbol = (gpointer)(intptr_t)GetProcAddress (module->handle, symbol_name);
return *symbol != NULL;
}
}
@@ -209,7 +212,7 @@ g_module_error (void)
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL,
code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 0, NULL);
- ret = g_strdup (buf);
+ ret = u16to8 (buf);
LocalFree(buf);
return ret;
View
71 eglib/src/gpath.c
@@ -25,23 +25,36 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <config.h>
#include <stdio.h>
#include <glib.h>
#include <errno.h>
#include <sys/types.h>
-#ifndef _MSC_VER
+#ifdef G_OS_UNIX
#include <pthread.h>
-#include <unistd.h>
+#endif
+
+#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef G_OS_WIN32
+#include <direct.h>
+#include <io.h>
+#endif
+
+
gchar *
g_build_path (const gchar *separator, const gchar *first_element, ...)
{
GString *result;
const char *s, *p, *next;
- int slen;
+ size_t slen;
va_list args;
g_return_val_if_fail (separator != NULL, NULL);
@@ -80,7 +93,7 @@ gchar *
g_path_get_dirname (const gchar *filename)
{
char *p, *r;
- int count;
+ size_t count;
g_return_val_if_fail (filename != NULL, NULL);
p = strrchr (filename, G_DIR_SEPARATOR);
@@ -139,7 +152,7 @@ g_path_is_absolute (const char *filename)
gchar *
g_find_program_in_path (const gchar *program)
{
- char *p = g_strdup (getenv ("PATH"));
+ char *p = g_strdup (g_getenv ("PATH"));
char *x = p, *l;
gchar *curdir = NULL;
char *save;
@@ -156,7 +169,7 @@ g_find_program_in_path (const gchar *program)
x = NULL;
probe_path = g_build_path (G_DIR_SEPARATOR_S, l, program, NULL);
- if (access (probe_path, X_OK) == 0){
+ if (access (probe_path, X_OK) == 0){ /* FIXME: on windows this is just a read permissions test */
g_free (curdir);
g_free (p);
return probe_path;
@@ -177,7 +190,7 @@ g_get_current_dir (void)
do {
buffer = g_realloc (buffer, s);
- r = getcwd (buffer, s);
+ r = getcwd (buffer, s);
fail = (r == NULL && errno == ERANGE);
if (fail) {
s <<= 1;
@@ -190,7 +203,7 @@ g_get_current_dir (void)
#if defined (G_OS_UNIX)
static pthread_mutex_t home_lock = PTHREAD_MUTEX_INITIALIZER;
-static char *home_dir;
+static const gchar *home_dir;
/* Give preference to /etc/passwd than HOME */
const gchar *
@@ -216,7 +229,7 @@ g_get_home_dir (void)
}
endpwent ();
if (home_dir == NULL)
- home_dir = getenv ("HOME");
+ home_dir = g_getenv ("HOME");
pthread_mutex_unlock (&home_lock);
}
}
@@ -230,7 +243,18 @@ const gchar *
g_get_home_dir (void)
{
/* FIXME */
- return getenv ("HOME");
+ const gchar *drive = g_getenv ("HOMEDRIVE");
+ const gchar *path = g_getenv ("HOMEPATH");
+ gchar *home_dir = NULL;
+
+ if (drive && path) {
+ home_dir = malloc(strlen(drive) + strlen(path) +1);
+ if (home_dir) {
+ sprintf(home_dir, "%s%s", drive, path);
+ }
+ }
+
+ return home_dir;
}
#else
@@ -244,36 +268,35 @@ g_get_home_dir (void)
#endif
-static char *tmp_dir;
-#ifdef _MSC_VER
-/* FIXME */
-#else
+static const char *tmp_dir;
+
+#ifdef G_OS_UNIX
static pthread_mutex_t tmp_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
const gchar *
g_get_tmp_dir (void)
{
if (tmp_dir == NULL){
-#ifdef _MSC_VER
-/* FIXME */
-#else
+#ifdef G_OS_UNIX
pthread_mutex_lock (&tmp_lock);
#endif
if (tmp_dir == NULL){
- tmp_dir = getenv ("TMPDIR");
+ tmp_dir = g_getenv ("TMPDIR");
if (tmp_dir == NULL){
- tmp_dir = getenv ("TMP");
+ tmp_dir = g_getenv ("TMP");
if (tmp_dir == NULL){
- tmp_dir = getenv ("TEMP");
+ tmp_dir = g_getenv ("TEMP");
if (tmp_dir == NULL)
+#if defined (G_OS_WIN32)
+ tmp_dir = "C:\\temp";
+#else
tmp_dir = "/tmp";
+#endif
}
}
}
-#ifdef _MSC_VER
-/* FIXME */
-#else
+#ifdef G_OS_UNIX
pthread_mutex_unlock (&tmp_lock);
#endif
}
@@ -283,7 +306,7 @@ g_get_tmp_dir (void)
const char *
g_get_user_name (void)
{
- return getenv ("USER");
+ return g_getenv ("USER");
}
static char *name;
View
7 eglib/src/gpattern.c
@@ -53,7 +53,7 @@ static GSList *
compile_pattern (const gchar *pattern)
{
GSList *list;
- gint i, len;
+ size_t i, len;
PData *data;
gchar c;
MatchType last = -1;
@@ -157,9 +157,9 @@ g_pattern_spec_free (GPatternSpec *pspec)
}
static gboolean
-match_string (GSList *list, const gchar *str, gint idx, gint max)
+match_string (GSList *list, const gchar *str, size_t idx, size_t max)
{
- gint len;
+ size_t len;
while (list && idx < max) {
PData *data = (PData *) list->data;
@@ -209,3 +209,4 @@ g_pattern_match_string (GPatternSpec *pspec, const gchar *string)
return match_string (pspec->pattern, string, 0, strlen (string));
}
+
View
7 eglib/src/gptrarray.c
@@ -38,7 +38,7 @@ typedef struct _GPtrArrayPriv {
static void
g_ptr_array_grow(GPtrArrayPriv *array, guint length)
{
- gint new_length = array->len + length;
+ guint new_length = array->len + length;
g_return_if_fail(array != NULL);
@@ -101,7 +101,7 @@ g_ptr_array_set_size(GPtrArray *array, gint length)
{
g_return_if_fail(array != NULL);
- if(length > array->len) {
+ if((size_t)length > array->len) {
g_ptr_array_grow((GPtrArrayPriv *)array, length);
memset(array->pdata + array->len, 0, (length - array->len)
* sizeof(gpointer));
@@ -159,7 +159,7 @@ g_ptr_array_remove(GPtrArray *array, gpointer data)
void
g_ptr_array_foreach(GPtrArray *array, GFunc func, gpointer user_data)
{
- gint i;
+ guint i;
for(i = 0; i < array->len; i++) {
func(g_ptr_array_index(array, i), user_data);
@@ -180,3 +180,4 @@ g_ptr_array_sort_with_data(GPtrArray *array, GCompareDataFunc compare_func,
}
+
View
44 eglib/src/gspawn.c
@@ -25,19 +25,37 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
-#ifdef _MSC_VER
-#include <winsock2.h>
-#else
+
+#include <glib.h>
+
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
-#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <io.h>
+#include <winsock2.h>
+#define open _open
+#define close _close
+#define read _read
+#define write _write
+/* windows pipe api details: http://msdn2.microsoft.com/en-us/library/edze9h7e(VS.80).aspx */
+#define pipe(x) _pipe(x, 256, 0)
+#endif
#define set_error(msg, ...) do { if (error != NULL) *error = g_error_new (G_LOG_DOMAIN, 1, msg, __VA_ARGS__); } while (0)
#define set_error_cond(cond,msg, ...) do { if ((cond) && error != NULL) *error = g_error_new (G_LOG_DOMAIN, 1, msg, __VA_ARGS__); } while (0)
@@ -83,12 +101,21 @@ read_pipes (int outfd, gchar **out_str, int errfd, gchar **err_str, GError **err
if (out_closed && err_closed)
break;
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable:4389)
+#endif
+
FD_ZERO (&rfds);
if (!out_closed && outfd >= 0)
FD_SET (outfd, &rfds);
if (!err_closed && errfd >= 0)
FD_SET (errfd, &rfds);
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
res = select (MAX (outfd, errfd) + 1, &rfds, NULL, NULL, NULL);
if (res > 0) {
if (buffer == NULL)
@@ -150,6 +177,8 @@ g_spawn_command_line_sync (const gchar *command_line,
gint *exit_status,
GError **error)
{
+#ifdef G_OS_WIN32
+#else
pid_t pid;
gchar **argv;
gint argc;
@@ -223,7 +252,7 @@ g_spawn_command_line_sync (const gchar *command_line,
if (WIFEXITED (status) && exit_status) {
*exit_status = WEXITSTATUS (status);
}
-
+#endif
return TRUE;
}
@@ -244,6 +273,8 @@ g_spawn_async_with_pipes (const gchar *working_directory,
gint *standard_error,
GError **error)
{
+#ifdef G_OS_WIN32
+#else
pid_t pid;
int info_pipe [2];
int in_pipe [2] = { -1, -1 };
@@ -411,7 +442,8 @@ g_spawn_async_with_pipes (const gchar *working_directory,
*standard_output = out_pipe [0];
if (standard_error)
*standard_error = err_pipe [0];
-
+#endif
return TRUE;
}
+
View
53 eglib/src/gstr.c
@@ -26,6 +26,7 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <config.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -35,7 +36,18 @@
gchar *
g_strndup (const gchar *str, gsize n)
{
+#ifdef HAVE_STRNDUP
return strndup (str, n);
+#else
+ if (str) {
+ char *retval = malloc(n);
+ if (retval) {
+ strncpy(retval, str, n)[n] = 0;
+ }
+ return retval;
+ }
+ return NULL;
+#endif
}
void
@@ -63,8 +75,8 @@ g_strv_length(gchar **str_array)
gboolean
g_str_has_suffix(const gchar *str, const gchar *suffix)
{
- gint str_length;
- gint suffix_length;
+ size_t str_length;
+ size_t suffix_length;
g_return_val_if_fail(str != NULL, FALSE);
g_return_val_if_fail(suffix != NULL, FALSE);
@@ -80,8 +92,8 @@ g_str_has_suffix(const gchar *str, const gchar *suffix)
gboolean
g_str_has_prefix(const gchar *str, const gchar *prefix)
{
- gint str_length;
- gint prefix_length;
+ size_t str_length;
+ size_t prefix_length;
g_return_val_if_fail(str != NULL, FALSE);
g_return_val_if_fail(prefix != NULL, FALSE);
@@ -133,7 +145,7 @@ gchar *
g_strconcat (const gchar *first, ...)
{
va_list args;
- int total = 0;
+ size_t total = 0;
char *s, *ret;
g_return_val_if_fail (first != NULL, NULL);
@@ -166,7 +178,7 @@ g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens)
gchar *strtok_save, **vector;
gchar *token, *token_c;
gint size = 1;
- gint token_length;
+ size_t token_length;
g_return_val_if_fail(string != NULL, NULL);
g_return_val_if_fail(delimiter != NULL, NULL);
@@ -227,8 +239,8 @@ g_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens)
gchar *
g_strreverse (gchar *str)
{
- guint len, half;
- gint i;
+ size_t len, half;
+ size_t i;
gchar c;
if (str == NULL)
@@ -250,7 +262,7 @@ g_strjoin (const gchar *separator, ...)
{
va_list args;
char *res, *s;
- int len, slen;
+ size_t len, slen;
if (separator != NULL)
slen = strlen (separator);
@@ -288,7 +300,7 @@ gchar *
g_strjoinv (const gchar *separator, gchar **str_array)
{
char *res;
- int slen, len, i;
+ size_t slen, len, i;
if (separator != NULL)
slen = strlen (separator);
@@ -318,7 +330,7 @@ g_strjoinv (const gchar *separator, gchar **str_array)
gchar *
g_strchug (gchar *str)
{
- gint len;
+ size_t len;
gchar *tmp;
if (str == NULL)
@@ -399,7 +411,7 @@ g_snprintf(gchar *string, gulong n, gchar const *format, ...)
return ret;
}
-static const char const hx [] = { '0', '1', '2', '3', '4', '5', '6', '7',
+static const char hx [] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
static gboolean
@@ -419,7 +431,7 @@ char_needs_encoding (char c)
gchar *
g_filename_to_uri (const gchar *filename, const gchar *hostname, GError **error)
{
- int n;
+ size_t n;
char *ret, *rp;
const char *p;
@@ -507,7 +519,7 @@ g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error)
for (p = uri + 8, r = result + 1; *p; p++){
if (*p == '%'){
- *r++ = (decode (p [1]) << 4) | decode (p [2]);
+ *r++ = (char)((decode (p [1]) << 4) | decode (p [2]));
p += 2;
} else
*r++ = *p;
@@ -522,7 +534,7 @@ g_strdown (gchar *string)
g_return_if_fail (string != NULL);
while (*string){
- *string = tolower (*string);
+ *string = (gchar)tolower (*string);
string++;
}
}
@@ -553,7 +565,7 @@ g_ascii_strdown (const gchar *str, gssize len)
gint
g_ascii_strncasecmp (const gchar *s1, const gchar *s2, gsize n)
{
- int i;
+ gsize i;
g_return_val_if_fail (s1 != NULL, 0);
g_return_val_if_fail (s2 != NULL, 0);
@@ -592,10 +604,12 @@ g_strdelimit (gchar *string, const gchar *delimiters, gchar new_delimiter)
return string;
}
-#ifndef HAVE_STRLCPY
gsize
g_strlcpy (gchar *dest, const gchar *src, gsize dest_size)
{
+#ifdef HAVE_STRLCPY
+ return strlcpy (dest, src, dest_size);
+#else
gchar *d;
const gchar *s;
gchar c;
@@ -622,8 +636,8 @@ g_strlcpy (gchar *dest, const gchar *src, gsize dest_size)
/* we need to return the length of src here */
while (*s++) ; /* instead of a plain strlen, we use 's' */
return s - src - 1;
-}
#endif
+}
static const gchar escaped_dflt [256] = {
1, 1, 1, 1, 1, 1, 1, 1, 'b', 't', 'n', 1, 'f', 'r', 1, 1,
@@ -650,7 +664,7 @@ g_strescape (const gchar *source, const gchar *exceptions)
gchar escaped [256];
const gchar *ptr;
gchar c;
- int op;
+ gchar op;
gchar *result;
gchar *res_ptr;
@@ -702,3 +716,4 @@ g_ascii_xdigit_value (gchar c)
}
+
View
41 eglib/src/gtimer.c
@@ -27,14 +27,19 @@
*/
#include <glib.h>
#ifdef _MSC_VER
-#include <winsock2.h>
+#include <windows.h>
#else
#include <sys/time.h>
#endif
struct _GTimer {
+#ifdef _MSC_VER
+ guint64 start;
+ guint64 stop;
+#else
struct timeval start;
struct timeval stop;
+#endif
};
GTimer *g_timer_new (void)
@@ -57,23 +62,51 @@ void
g_timer_start (GTimer *timer)
{
g_return_if_fail (timer != NULL);
+#ifdef _MSC_VER
+ QueryPerformanceCounter ((LARGE_INTEGER*)&timer->start);
+#else
gettimeofday (&timer->start, NULL);
memset (&timer->stop, 0, sizeof (struct timeval));
+#endif
+
}
void
g_timer_stop (GTimer *timer)
{
g_return_if_fail (timer != NULL);
+#ifdef _MSC_VER
+ QueryPerformanceCounter ((LARGE_INTEGER*)&timer->stop);
+#else
gettimeofday (&timer->stop, NULL);
+#endif
}
gdouble
g_timer_elapsed (GTimer *timer, gulong *microseconds)
{
+#ifdef _MSC_VER
+ guint64 stop;
+ guint64 freq;
+ gdouble seconds;
+ if (timer->stop == 0) {
+ QueryPerformanceCounter ((LARGE_INTEGER*)&stop);
+ }
+ else {
+ stop = timer->stop;
+ }
+
+ QueryPerformanceFrequency ((LARGE_INTEGER*)&freq);
+ seconds = 1.0 * (stop - timer->start) / freq;
+
+ if (microseconds) {
+ *microseconds = (gulong)(1000000.0 * (stop - timer->start) / freq);
+ }
+ return seconds;
+#else
struct timeval tv;
gulong seconds;
- gulong usec;
+ long usec;
gdouble result;
g_return_val_if_fail (timer != NULL, 0.0);
@@ -84,7 +117,7 @@ g_timer_elapsed (GTimer *timer, gulong *microseconds)
tv = timer->stop;
}
- usec = tv.tv_usec - timer->start.tv_usec;
+ usec = (tv.tv_usec) - (timer->start.tv_usec);
seconds = tv.tv_sec - timer->start.tv_sec;
if (microseconds) {
if (usec < 0) {
@@ -95,5 +128,7 @@ g_timer_elapsed (GTimer *timer, gulong *microseconds)
}
result = seconds * 1000000 + usec;
return (result / 1000000);
+#endif
}
+
View
17 eglib/src/gunicode.c
@@ -67,11 +67,14 @@ g_convert (const gchar *str, gssize len,
const gchar *to_codeset, const gchar *from_codeset,
gsize *bytes_read, gsize *bytes_written, GError **error)
{
+ char *result = NULL;
+#ifdef G_OS_WIN32
+#else
iconv_t convertor;
- char *buffer, *result, *output;
+ char *buffer, *output;
const char *strptr = (const char *) str;
- int str_len = len == -1 ? strlen (str) : len;
- int buffer_size;
+ size_t str_len = len == -1 ? strlen (str) : len;
+ size_t buffer_size;
size_t left, out_left;
convertor = iconv_open (to_codeset, from_codeset);
@@ -91,8 +94,8 @@ g_convert (const gchar *str, gssize len,
if (res == (size_t) -1){
if (errno == E2BIG){
char *n;
- int extra_space = 8 + left;
- int output_used = output - buffer;
+ size_t extra_space = 8 + left;
+ size_t output_used = output - buffer;
buffer_size += extra_space;
@@ -131,6 +134,7 @@ g_convert (const gchar *str, gssize len,
result = buffer;
leave:
iconv_close (convertor);
+#endif
return result;
}
@@ -153,6 +157,8 @@ g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read, gs
gboolean
g_get_charset (G_CONST_RETURN char **charset)
{
+#ifdef G_OS_WIN32
+#else
if (my_charset == NULL){
my_charset = g_strdup (nl_langinfo (CODESET));
is_utf8 = strcmp (my_charset, "UTF-8") == 0;
@@ -161,6 +167,7 @@ g_get_charset (G_CONST_RETURN char **charset)
if (charset != NULL)
*charset = my_charset;
+#endif
return is_utf8;
}
View
10 eglib/src/gutf8.c
@@ -86,12 +86,12 @@ g_utf8_to_utf16 (const gchar *str, glong len, glong *items_read, glong *items_wr
if (--mb_remain == 0) {
/* multi byte character is fully consumed now. */
if (codepoint < 0x10000) {
- ret [out_pos++] = codepoint % 0x10000;
+ ret [out_pos++] = (gunichar2)(codepoint % 0x10000);
} else if (codepoint < 0x110000) {
/* surrogate pair */
codepoint -= 0x10000;
- ret [out_pos++] = (codepoint >> 10) + 0xD800;
- ret [out_pos++] = (codepoint & 0x3FF) + 0xDC00;
+ ret [out_pos++] = (gunichar2)((codepoint >> 10) + 0xD800);
+ ret [out_pos++] = (gunichar2)((codepoint & 0x3FF) + 0xDC00);
} else {
/* invalid utf-8 sequence (excess) */
codepoint = 0;
@@ -247,7 +247,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
gchar *ret;
glong in_pos, out_pos;
gunichar2 ch;
- guint32 codepoint;
+ guint32 codepoint = 0;
gboolean surrogate;
in_pos = 0;
@@ -279,7 +279,7 @@ g_utf16_to_utf8 (const gunichar2 *str, glong len, glong *items_read, glong *item
if (ch < 0x80) {
for (; len < 0 ? str [in_pos] : in_pos < len; in_pos++) {
if (str [in_pos] < 0x80)
- ret [out_pos++] = str [in_pos];
+ ret [out_pos++] = (gchar)(str [in_pos]);
else
break;
}
View
6 eglib/test/dir.c
@@ -1,8 +1,13 @@
+#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#ifdef G_OS_UNIX
#include <pthread.h>
+#endif
#include "test.h"
/* This test is just to be used with valgrind */
@@ -58,3 +63,4 @@ static Test dir_tests [] = {
DEFINE_TEST_GROUP_INIT(dir_tests_init, dir_tests)
+
View
29 eglib/test/driver.c
@@ -25,14 +25,22 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-
-#include <stdio.h>
-#include <glib.h>
-#include <getopt.h>
+#include <config.h>
#include "test.h"
#include "tests.h"
+#include <stdio.h>
+#include <getopt.h>
+
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+
+#ifndef DRIVER_NAME
+#define DRIVER_NAME "EGlib"
+#endif
+
typedef struct _StringArray {
gchar **strings;
gint length;
@@ -57,6 +65,8 @@ string_array_append(StringArray *array, gchar *string)
return array;
}
+gint global_passed = 0, global_tests = 0;
+
static void
string_array_free(StringArray *array)
{
@@ -155,8 +165,8 @@ gint main(gint argc, gchar **argv)
for(k = 0; k < tests_to_run->length; k++) {
gchar *user = tests_to_run->strings[k];
const gchar *table = test_groups[j].name;
- gint user_len = strlen(user);
- gint table_len = strlen(table);
+ size_t user_len = strlen(user);
+ size_t table_len = strlen(table);
if(strncmp(user, table, table_len) == 0) {
if(user_len > table_len && user[table_len] != ':') {
@@ -171,6 +181,7 @@ gint main(gint argc, gchar **argv)
}
if(run) {
+ gboolean passed;
gchar **split = NULL;
if(debug && test_groups[j].handler != fake_tests_init) {
@@ -195,7 +206,7 @@ gint main(gint argc, gchar **argv)
}
}
- gboolean passed = run_group(&(test_groups[j]),
+ passed = run_group(&(test_groups[j]),
iterations, quiet, report_time, tests);
if(tests != NULL) {
@@ -209,8 +220,9 @@ gint main(gint argc, gchar **argv)
}
if(!quiet) {
+ gdouble pass_percentage = ((gdouble)global_passed / (gdouble)global_tests) * 100.0;
printf("=============================\n");
- printf("Overall result: %s\n", global_failure ? "FAILED" : "OK");
+ printf("Overall result: %s : %d / %d (%g%%)\n", global_failure ? "FAILED" : "OK", global_passed, global_tests, pass_percentage);
}
if(report_time) {
@@ -229,3 +241,4 @@ gint main(gint argc, gchar **argv)
return 0;
}
+
View
26 eglib/test/file.c
@@ -1,17 +1,30 @@
+#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <stdio.h>
#include "test.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#define close _close
+#endif
+
RESULT
test_file_get_contents ()
{
GError *error;
gchar *content;
gboolean ret;
gsize length;
+#ifdef G_OS_WIN32
+ const gchar *filename = "c:\\Windows\\system.ini";
+#else
+ const gchar *filename = "/etc/hosts";
+#endif
/*
filename != NULL
@@ -33,7 +46,7 @@ test_file_get_contents ()
g_error_free (error);
error = NULL;
- ret = g_file_get_contents ("/etc/hosts", &content, &length, &error);
+ ret = g_file_get_contents (filename, &content, &length, &error);
if (!ret)
return FAILED ("The error is %d %s\n", error->code, error->message);
if (error != NULL)
@@ -98,8 +111,12 @@ test_file ()
{
gboolean res;
const gchar *tmp;
- gchar *path, *sympath;
+ gchar *path;
+
+#ifndef G_OS_WIN32 /* FIXME */
+ gchar *sympath;
gint ignored;
+#endif
res = g_file_test (NULL, 0);
if (res)
@@ -156,6 +173,7 @@ test_file ()
if (res)
return FAILED ("3 %s should not be a symlink", path);
+#ifndef G_OS_WIN32 /* FIXME */
sympath = g_strconcat (path, "-link", NULL);
ignored = symlink (path, sympath);
res = g_file_test (sympath, G_FILE_TEST_EXISTS);
@@ -192,8 +210,9 @@ test_file ()
if (!res)
return FAILED ("5 %s should be a symlink", sympath);
unlink (sympath);
- g_free (path);
g_free (sympath);
+#endif
+ g_free (path);
return OK;
}
@@ -206,3 +225,4 @@ static Test file_tests [] = {
DEFINE_TEST_GROUP_INIT(file_tests_init, file_tests)
+
View
4 eglib/test/list.c
@@ -315,10 +315,12 @@ static int intcompare (gconstpointer p1, gconstpointer p2)
static gboolean verify_sort (GList *list, int len)
{
+ int prev;
+
if (list->prev)
return FALSE;
- int prev = GPOINTER_TO_INT (list->data);
+ prev = GPOINTER_TO_INT (list->data);
len--;
for (list = list->next; list; list = list->next) {
int curr = GPOINTER_TO_INT (list->data);
View
4 eglib/test/module.c
@@ -1,8 +1,11 @@
+#include <config.h>
#include <glib.h>
#include <gmodule.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include "test.h"
#if defined (G_OS_WIN32)
@@ -58,3 +61,4 @@ static Test module_tests [] = {
DEFINE_TEST_GROUP_INIT(module_tests_init, module_tests)
+
View
88 eglib/test/path.c
@@ -1,10 +1,20 @@
+#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#ifdef G_OS_UNIX
#include <pthread.h>
+#endif
#include "test.h"
+#ifdef G_OS_WIN32
+#include <direct.h>
+#define chdir _chdir
+#endif
+
/* This test is just to be used with valgrind */
RESULT
test_buildpath ()
@@ -82,7 +92,6 @@ test_buildpath ()
if (strcmp (s, "/a/c/") != 0)
return FAILED ("14 Got wrong result, got: %s", s);
g_free (s);
- return OK;
return OK;
}
@@ -93,7 +102,11 @@ test_buildfname ()
char *s;
s = g_build_filename ("a", "b", "c", "d", NULL);
+#ifdef G_OS_WIN32
+ if (strcmp (s, "a\\b\\c\\d") != 0)
+#else
if (strcmp (s, "a/b/c/d") != 0)
+#endif
return FAILED ("1 Got wrong result, got: %s", s);
g_free (s);
@@ -105,6 +118,26 @@ test_dirname ()
{
char *s;
+#ifdef G_OS_WIN32
+ s = g_path_get_dirname ("c:\\home\\miguel");
+ if (strcmp (s, "c:\\home") != 0)
+ return FAILED ("Expected c:\\home, got %s", s);
+ g_free (s);
+
+ s = g_path_get_dirname ("c:\\home\\dingus\\");
+ if (strcmp (s, "c:\\home\\dingus") != 0)
+ return FAILED ("Expected c:\\home\\dingus, got %s", s);
+ g_free (s);
+
+ s = g_path_get_dirname ("dir.c");
+ if (strcmp (s, ".") != 0)
+ return FAILED ("Expected `.', got %s", s);
+ g_free (s);
+
+ s = g_path_get_dirname ("c:\\index.html");
+ if (strcmp (s, "c:") != 0)
+ return FAILED ("Expected [c:], got [%s]", s);
+#else
s = g_path_get_dirname ("/home/miguel");
if (strcmp (s, "/home") != 0)
return FAILED ("Expected /home, got %s", s);
@@ -123,7 +156,7 @@ test_dirname ()
s = g_path_get_dirname ("/index.html");
if (strcmp (s, "/") != 0)
return FAILED ("Expected [/], got [%s]", s);
-
+#endif
return OK;
}
@@ -132,6 +165,22 @@ test_basename ()
{
char *s;
+#ifdef G_OS_WIN32
+ s = g_path_get_basename ("");
+ if (strcmp (s, ".") != 0)
+ return FAILED ("Expected `.', got %s", s);
+ g_free (s);
+
+ s = g_path_get_basename ("c:\\home\\dingus\\");
+ if (strcmp (s, "dingus") != 0)
+ return FAILED ("1 Expected dingus, got %s", s);
+ g_free (s);
+
+ s = g_path_get_basename ("c:\\home\\dingus");
+ if (strcmp (s, "dingus") != 0)
+ return FAILED ("2 Expected dingus, got %s", s);
+ g_free (s);
+#else
s = g_path_get_basename ("");
if (strcmp (s, ".") != 0)
return FAILED ("Expected `.', got %s", s);
@@ -146,18 +195,22 @@ test_basename ()
if (strcmp (s, "dingus") != 0)
return FAILED ("2 Expected dingus, got %s", s);
g_free (s);
-
+#endif
return OK;
}
gchar *
test_ppath ()
{
char *s;
-
- s = g_find_program_in_path ("ls");
+#ifdef G_OS_WIN32
+ const gchar *searchfor = "explorer.exe";
+#else
+ const gchar *searchfor = "ls";
+#endif
+ s = g_find_program_in_path (searchfor);
if (s == NULL)
- return FAILED ("No shell on this system (This assumes Unix)?");
+ return FAILED ("No %s on this system?", searchfor);
g_free (s);
return OK;
}
@@ -167,6 +220,11 @@ test_ppath2 ()
{
char *s;
const char *path = g_getenv ("PATH");
+#ifdef G_OS_WIN32
+ const gchar *searchfor = "test_eglib.exe";
+#else
+ const gchar *searchfor = "test-glib";
+#endif
g_setenv ("PATH", "", TRUE);
s = g_find_program_in_path ("ls");
@@ -175,10 +233,10 @@ test_ppath2 ()
return FAILED ("Found something interesting here: %s", s);
}
g_free (s);
- s = g_find_program_in_path ("test-glib");
+ s = g_find_program_in_path (searchfor);
if (s == NULL) {
g_setenv ("PATH", path, TRUE);
- return FAILED ("It should find 'test-glib' in the current directory.");
+ return FAILED ("It should find '%s' in the current directory.", searchfor);
}
g_free (s);
g_setenv ("PATH", path, TRUE);
@@ -189,17 +247,22 @@ gchar *
test_cwd ()
{
char *dir = g_get_current_dir ();
+#ifdef G_OS_WIN32
+ const gchar *newdir = "C:\\Windows";
+#else
+ const gchar *newdir = "/bin";
+#endif
if (dir == NULL)
return FAILED ("No current directory?");
g_free (dir);
- if (chdir ("/bin") == -1)
- return FAILED ("No /bin?");
+ if (chdir (newdir) == -1)
+ return FAILED ("No %s?", newdir);
dir = g_get_current_dir ();
- if (strcmp (dir, "/bin") != 0)
- return FAILED("Did not go to /bin?");
+ if (strcmp (dir, newdir) != 0)
+ return FAILED("Did not go to %s?", newdir);
g_free (dir);
return OK;
@@ -234,3 +297,4 @@ static Test path_tests [] = {
DEFINE_TEST_GROUP_INIT(path_tests_init, path_tests)
+
View
4 eglib/test/pattern.c
@@ -1,7 +1,10 @@
+#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <stdio.h>
#include "test.h"
@@ -55,3 +58,4 @@ static Test pattern_tests [] = {
DEFINE_TEST_GROUP_INIT(pattern_tests_init, pattern_tests)
+
View
19 eglib/test/ptrarray.c
@@ -17,7 +17,7 @@ static const char *items [] = {
NULL
};
-static GPtrArray *ptrarray_alloc_and_fill(gint *item_count)
+static GPtrArray *ptrarray_alloc_and_fill(guint *item_count)
{
GPtrArray *array = g_ptr_array_new();
gint i;
@@ -33,9 +33,9 @@ static GPtrArray *ptrarray_alloc_and_fill(gint *item_count)
return array;
}
-static gint guess_size(gint length)
+static guint guess_size(guint length)
{
- gint size = 1;
+ guint size = 1;
while(size < length) {
size <<= 1;
@@ -47,7 +47,7 @@ static gint guess_size(gint length)
RESULT ptrarray_alloc()
{
GPtrArrayPriv *array;
- gint i;
+ guint i;
array = (GPtrArrayPriv *)ptrarray_alloc_and_fill(&i);
@@ -68,7 +68,7 @@ RESULT ptrarray_alloc()
RESULT ptrarray_for_iterate()
{
GPtrArray *array = ptrarray_alloc_and_fill(NULL);
- gint i;
+ guint i;
for(i = 0; i < array->len; i++) {
char *item = (char *)g_ptr_array_index(array, i);
@@ -120,7 +120,7 @@ RESULT ptrarray_foreach_iterate()
RESULT ptrarray_set_size()
{
GPtrArray *array = g_ptr_array_new();
- gint i, grow_length = 50;
+ guint i, grow_length = 50;
g_ptr_array_add(array, (gpointer)items[0]);
g_ptr_array_add(array, (gpointer)items[1]);
@@ -148,7 +148,7 @@ RESULT ptrarray_set_size()
RESULT ptrarray_remove_index()
{
GPtrArray *array;
- gint i;
+ guint i;
array = ptrarray_alloc_and_fill(&i);
@@ -173,7 +173,7 @@ RESULT ptrarray_remove_index()
RESULT ptrarray_remove()
{
GPtrArray *array;
- gint i;
+ guint i;
array = ptrarray_alloc_and_fill(&i);
@@ -206,7 +206,7 @@ static gint ptrarray_sort_compare(gconstpointer a, gconstpointer b)
RESULT ptrarray_sort()
{
GPtrArray *array = g_ptr_array_new();
- gint i;
+ guint i;
gchar *letters [] = { "A", "B", "C", "D", "E" };
g_ptr_array_add(array, letters[0]);
@@ -242,3 +242,4 @@ static Test ptrarray_tests [] = {
DEFINE_TEST_GROUP_INIT(ptrarray_tests_init, ptrarray_tests)
+
View
2 eglib/test/sizes.c
@@ -4,7 +4,9 @@
* These depend on -Werror, -Wall being set to catch the build error.
*/
#include <stdio.h>
+#ifndef _MSC_VER
#include <stdint.h>
+#endif
#include <string.h>
#include <glib.h>
#include "test.h"
View
10 eglib/test/spawn.c
@@ -1,9 +1,18 @@
+#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include "test.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#define read _read
+#define close _close
+#endif
+
RESULT
test_spawn_sync ()
{
@@ -70,3 +79,4 @@ static Test spawn_tests [] = {
DEFINE_TEST_GROUP_INIT(spawn_tests_init, spawn_tests)
+
View
38 eglib/test/string-util.c
@@ -254,6 +254,7 @@ RESULT
test_ascii_xdigit_value ()
{
int i;
+ gchar j;
i = g_ascii_xdigit_value ('9' + 1);
if (i != -1)
@@ -274,20 +275,20 @@ test_ascii_xdigit_value ()
if (i != -1)
return FAILED ("'F' + 1");
- for (i = '0'; i < '9'; i++) {
- int c = g_ascii_xdigit_value (i);
- if (c != (i - '0'))
- return FAILED ("Digits %c -> %d", i, c);
+ for (j = '0'; j < '9'; j++) {
+ int c = g_ascii_xdigit_value (j);
+ if (c != (j - '0'))
+ return FAILED ("Digits %c -> %d", j, c);
}
- for (i = 'a'; i < 'f'; i++) {
- int c = g_ascii_xdigit_value (i);
- if (c != (i - 'a' + 10))
- return FAILED ("Lower %c -> %d", i, c);
+ for (j = 'a'; j < 'f'; j++) {
+ int c = g_ascii_xdigit_value (j);
+ if (c != (j - 'a' + 10))
+ return FAILED ("Lower %c -> %d", j, c);
}
- for (i = 'A'; i < '