summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDom Lachowicz <domlachowicz@gmail.com>2009-05-22 20:51:41 +0000
committerDom Lachowicz <domlachowicz@gmail.com>2009-05-22 20:51:41 +0000
commit37279c6e3821c5499287a62fe3ea7b11eb6bc853 (patch)
tree282006bc1c1027094eb279a719e85699f5ee2475
parentd4f0ba7cf332d9e42548ecd869a000b91d5d0e5e (diff)
downloadenchant-37279c6e3821c5499287a62fe3ea7b11eb6bc853.tar.gz
Duplicate the code from Glib's g_fopen function, so that Enchant and Glib
don't necessarily have to be built against the same C runtime. git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@26478 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/enchant-provider.h4
-rw-r--r--src/enchant.c39
-rw-r--r--src/ispell/lookup.cpp5
-rw-r--r--src/pwl.c15
-rw-r--r--tests/enchant-ispell.c15
5 files changed, 59 insertions, 19 deletions
diff --git a/src/enchant-provider.h b/src/enchant-provider.h
index 064808c..88653a5 100644
--- a/src/enchant-provider.h
+++ b/src/enchant-provider.h
@@ -33,6 +33,7 @@
#include <enchant.h>
#include <glib.h>
+#include <stdio.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -70,6 +71,9 @@ ENCHANT_MODULE_EXPORT(void)
ENCHANT_MODULE_EXPORT(void)
enchant_provider_set_error (EnchantProvider * provider, const char * const err);
+ENCHANT_MODULE_EXPORT(FILE *)
+ enchant_fopen (const gchar *filename, const gchar *mode);
+
struct str_enchant_dict
{
void *user_data;
diff --git a/src/enchant.c b/src/enchant.c
index 0219ff1..0e1b153 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -286,6 +286,43 @@ enchant_get_conf_dirs (void)
return conf_dirs;
}
+ENCHANT_MODULE_EXPORT(FILE *)
+enchant_fopen (const gchar *filename, const gchar *mode)
+{
+#ifdef G_OS_WIN32
+ wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
+ wchar_t *wmode;
+ FILE *retval;
+ int save_errno;
+
+ if (wfilename == NULL)
+ {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
+
+ if (wmode == NULL)
+ {
+ g_free (wfilename);
+ errno = EINVAL;
+ return NULL;
+ }
+
+ retval = _wfopen (wfilename, wmode);
+ save_errno = errno;
+
+ g_free (wfilename);
+ g_free (wmode);
+
+ errno = save_errno;
+ return retval;
+#else
+ return fopen (filename, mode);
+#endif
+}
+
/**
* enchant_get_user_config_dir
*
@@ -1470,7 +1507,7 @@ enchant_load_ordering_from_file (EnchantBroker * broker, const char * file)
FILE * f;
- f = g_fopen (file, "r");
+ f = enchant_fopen (file, "r");
if (!f)
return;
diff --git a/src/ispell/lookup.cpp b/src/ispell/lookup.cpp
index 5a7e13b..6f9b17e 100644
--- a/src/ispell/lookup.cpp
+++ b/src/ispell/lookup.cpp
@@ -244,8 +244,7 @@
#include <string.h>
#include <ctype.h>
-#include <glib/gstdio.h>
-
+#include "enchant-provider.h"
#include "ispell_checker.h"
#include "msgs.h"
@@ -279,7 +278,7 @@ int ISpellChecker::linit (char *hashname)
int viazero;
register ichar_t * cp;
- if ((fpHash = g_fopen (hashname, "rb")) == NULL)
+ if ((fpHash = enchant_fopen (hashname, "rb")) == NULL)
{
return (-1);
}
diff --git a/src/pwl.c b/src/pwl.c
index 0f8cfed..5828c90 100644
--- a/src/pwl.c
+++ b/src/pwl.c
@@ -67,6 +67,7 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include "enchant-provider.h"
#include "pwl.h"
@@ -258,17 +259,17 @@ EnchantPWL* enchant_pwl_init(void)
*/
EnchantPWL* enchant_pwl_init_with_file(const char * file)
{
- int fd;
+ FILE* fd;
EnchantPWL *pwl;
g_return_val_if_fail (file != NULL, NULL);
- fd = g_open(file, O_CREAT | O_RDONLY, S_IREAD | S_IWRITE);
- if(fd == -1)
+ fd = enchant_fopen(file, "wb");
+ if(fd == NULL)
{
return NULL;
}
- close(fd);
+ fclose(fd);
pwl = enchant_pwl_init();
pwl->filename = g_strdup(file);
pwl->file_changed = 0;
@@ -299,7 +300,7 @@ static void enchant_pwl_refresh_from_file(EnchantPWL* pwl)
g_hash_table_destroy (pwl->words_in_trie);
pwl->words_in_trie = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- f = g_fopen(pwl->filename, "r");
+ f = enchant_fopen(pwl->filename, "r");
if (!f)
return;
@@ -393,7 +394,7 @@ void enchant_pwl_add(EnchantPWL *pwl,
{
FILE *f;
- f = g_fopen(pwl->filename, "a");
+ f = enchant_fopen(pwl->filename, "a");
if (f)
{
struct stat stats;
@@ -433,7 +434,7 @@ void enchant_pwl_remove(EnchantPWL *pwl,
if(!g_file_get_contents(pwl->filename, &contents, &length, NULL))
return;
- f = g_fopen(pwl->filename, "wb"); /*binary because g_file_get_contents reads binary*/
+ f = enchant_fopen(pwl->filename, "wb"); /*binary because g_file_get_contents reads binary*/
if (f)
{
const gunichar BOM = 0xfeff;
diff --git a/tests/enchant-ispell.c b/tests/enchant-ispell.c
index 0e04a30..331fb9c 100644
--- a/tests/enchant-ispell.c
+++ b/tests/enchant-ispell.c
@@ -44,7 +44,6 @@
#include <string.h>
#include <locale.h>
#include <glib.h>
-#include <glib/gstdio.h>
#include "enchant.h"
#include "enchant-provider.h"
@@ -138,7 +137,7 @@ do_mode_a (FILE * out, EnchantDict * dict, GString * word, size_t start_pos, siz
if (word->len <= MIN_WORD_LENGTH || enchant_dict_check (dict, word->str, word->len) == 0) {
if (lineCount)
- fprintf (out, "* %ld\n", lineCount);
+ fprintf (out, "* %u\n", (unsigned int)lineCount);
else
fwrite ("*\n", 1, 2, out);
}
@@ -148,18 +147,18 @@ do_mode_a (FILE * out, EnchantDict * dict, GString * word, size_t start_pos, siz
if (!n_suggs || !suggs) {
fwrite ("# ", 1, 2, out);
if (lineCount)
- fprintf (out, "%ld ", lineCount);
+ fprintf (out, "%u ", (unsigned int)lineCount);
print_utf (out, word->str);
- fprintf (out, " %ld\n", start_pos);
+ fprintf (out, " %u\n", (unsigned int)start_pos);
}
else {
size_t i = 0;
fwrite ("& ", 1, 2, out);
if (lineCount)
- fprintf (out, "%ld ", lineCount);
+ fprintf (out, "%u ", (unsigned int)lineCount);
print_utf (out, word->str);
- fprintf (out, " %ld %ld:", n_suggs, start_pos);
+ fprintf (out, " %u %u:", (unsigned int)n_suggs, (unsigned int)start_pos);
for (i = 0; i < n_suggs; i++) {
fprintf (out, " ");
@@ -181,7 +180,7 @@ do_mode_l (FILE * out, EnchantDict * dict, GString * word, size_t lineCount)
{
if (enchant_dict_check (dict, word->str, word->len) != 0) {
if (lineCount)
- fprintf (out, "%ld ", lineCount);
+ fprintf (out, "%u ", (unsigned int)lineCount);
print_utf (out, word->str);
fwrite ("\n", 1, 1, out);
}
@@ -514,7 +513,7 @@ int main (int argc, char ** argv)
}
else {
if (file) {
- fp = g_fopen (file, "rb");
+ fp = enchant_fopen (file, "rb");
if (!fp) {
fprintf (stderr, "Error: Could not open the file \"%s\" for reading.\n", file);
exit (1);