Win/MSVC compatibility: Replace g_* file operations by the direct calls into the MSVC runtime.

This tries to avoid a collision between glib's C runtime vs.
the one that is used by MSVC (and hence also Qt) by using
file access only through MSVC's one.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19019 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2010-04-12 19:20:54 +00:00
parent 891c051f83
commit 08c36773ec
8 changed files with 64 additions and 9 deletions

View File

@ -11,6 +11,10 @@
#include "config.h"
#include "gfec.h"
#include "platform.h"
#if COMPILER(MSVC)
# define strdup _strdup
#endif
/* We assume that data is actually a char**. The way we return results

View File

@ -13,6 +13,7 @@ AM_CPPFLAGS = \
-I${top_srcdir}/src/gnc-module \
-I${top_srcdir}/lib/libc\
-I${top_srcdir}/src/libqof/qof \
-I$(top_srcdir)/src \
${LIBXML2_CFLAGS} \
${GLIB_CFLAGS} \
${GCONF_CFLAGS}

View File

@ -59,8 +59,10 @@ typedef int ssize_t;
# define read _read
# define write _write
#endif
#ifdef _MSC_VER
#include "platform.h"
#if COMPILER(MSVC)
# define g_fopen fopen
# define g_open _open
#endif
#include "qof.h"
@ -248,7 +250,9 @@ xml_session_begin(QofBackend *be_start, QofSession *session,
/* Again check whether the directory can be accessed */
rc = g_stat (be->dirname, &statbuf);
if (rc != 0
#ifndef _MSC_VER
#if COMPILER(MSVC)
|| (statbuf.st_mode & _S_IFDIR) == 0
#else
|| !S_ISDIR(statbuf.st_mode)
#endif
)
@ -278,7 +282,9 @@ xml_session_begin(QofBackend *be_start, QofSession *session,
return;
}
if (rc == 0
#ifndef _MSC_VER
#if COMPILER(MSVC)
&& (statbuf.st_mode & _S_IFDIR) != 0
#else
&& S_ISDIR(statbuf.st_mode)
#endif
)
@ -1201,3 +1207,10 @@ gnc_module_init_backend_xml(void)
}
/* ========================== END OF FILE ===================== */
/* For emacs we set some variables concerning indentation:
* Local Variables: *
* indent-tabs-mode:nil *
* c-basic-offset:4 *
* tab-width:8 *
* End: */

View File

@ -51,6 +51,10 @@
#include "Scrub.h"
#include "TransLog.h"
#include "platform.h"
#if COMPILER(MSVC)
# define g_fopen fopen
#endif
static QofLogModule log_module = GNC_MOD_IO;

View File

@ -54,8 +54,10 @@
# define fdopen _fdopen
# define read _read
#endif
#ifdef _MSC_VER
#include "platform.h"
#if COMPILER(MSVC)
# define g_fopen fopen
# define g_open _open
#endif
/* Do not treat -Wstrict-aliasing warnings as errors because of problems of the
@ -1385,7 +1387,13 @@ gz_thread_func(gz_thread_params_t *params)
gzval = gzread(file, buffer, BUFLEN);
if (gzval > 0)
{
if (write(params->fd, buffer, gzval) < 0)
if (
#if COMPILER(MSVC)
_write
#else
write
#endif
(params->fd, buffer, gzval) < 0)
{
g_warning("Could not write to pipe. The error is '%s' (%d)",
g_strerror(errno) ? g_strerror(errno) : "", errno);
@ -2083,3 +2091,10 @@ gnc_xml2_parse_with_subst (FileBackend *fbe, QofBook *book, GHashTable *subst)
return success;
}
/* For emacs we set some variables concerning indentation:
* Local Variables: *
* indent-tabs-mode:nil *
* c-basic-offset:4 *
* tab-width:8 *
* End: */

View File

@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES (${LIBINTL_INCLUDE_PATH})
INCLUDE_DIRECTORIES (${REGEX_INCLUDE_PATH})
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/.. ) # for config.h
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/lib/libc) # for strptime.h
INCLUDE_DIRECTORIES (${CMAKE_SOURCE_DIR}/src) # for platform.h
# Workaround to create a very simple gncla-dir.h file

View File

@ -8,6 +8,7 @@ libgnc_qof_la_LIBADD= \
AM_CPPFLAGS = \
-I$(top_srcdir)/lib/libc \
-I$(top_srcdir)/src \
$(GLIB_CFLAGS)
libgnc_qof_la_SOURCES = \

View File

@ -52,6 +52,7 @@
#ifndef HAVE_LOCALTIME_R
#include "localtime_r.h"
#endif
#include "platform.h"
#define NANOS_PER_SECOND 1000000000
@ -1420,10 +1421,18 @@ gnc_timezone (const struct tm *tm)
* already adjusted for daylight savings time. */
return -(tm->tm_gmtoff);
#else
/* timezone is seconds *west* of UTC and is
* not adjusted for daylight savings time.
* In Spring, we spring forward, wheee! */
return (long int)(timezone - (tm->tm_isdst > 0 ? 3600 : 0));
{
long tz_seconds;
/* timezone is seconds *west* of UTC and is
* not adjusted for daylight savings time.
* In Spring, we spring forward, wheee! */
# if COMPILER(MSVC)
_get_timezone(&tz_seconds);
# else
tz_seconds = timezone;
# endif
return (long int)(tz_seconds - (tm->tm_isdst > 0 ? 3600 : 0));
}
#endif
}
@ -1571,3 +1580,10 @@ timespec_get_type( void )
return type;
}
/* For emacs we set some variables concerning indentation:
* Local Variables: *
* indent-tabs-mode:nil *
* c-basic-offset:4 *
* tab-width:8 *
* End: */