Use g_stat() instead of stat() to prevent file read errors on Win32.
Prevent unnecessary filename encoding conversions on Win32. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1456 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
05164ab8ae
commit
e331c40a54
@ -1,3 +1,10 @@
|
|||||||
|
2007-04-16 Enrico Tröger <enrico.troeger@uvena.de>
|
||||||
|
|
||||||
|
* src/build.c, src/dialogs.c, src/document.c, src/utils.c:
|
||||||
|
Use g_stat() instead of stat() to prevent file read errors on Win32.
|
||||||
|
Prevent unnecessary filename encoding conversions on Win32.
|
||||||
|
|
||||||
|
|
||||||
2007-04-16 Nick Treleaven <nick.treleaven@btinternet.com>
|
2007-04-16 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||||
|
|
||||||
* src/filetypes.c:
|
* src/filetypes.c:
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#ifdef G_OS_UNIX
|
#ifdef G_OS_UNIX
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
@ -153,7 +154,7 @@ static GPid build_view_tex_file(gint idx, gint mode)
|
|||||||
locale_filename = utils_get_locale_from_utf8(view_file);
|
locale_filename = utils_get_locale_from_utf8(view_file);
|
||||||
|
|
||||||
// check wether view_file exists
|
// check wether view_file exists
|
||||||
if (stat(locale_filename, &st) != 0)
|
if (g_stat(locale_filename, &st) != 0)
|
||||||
{
|
{
|
||||||
msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file);
|
msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file);
|
||||||
utils_free_pointers(executable, view_file, locale_filename, NULL);
|
utils_free_pointers(executable, view_file, locale_filename, NULL);
|
||||||
@ -354,9 +355,9 @@ static GPid build_link_file(gint idx)
|
|||||||
object_file = g_strdup_printf("%s.o", executable);
|
object_file = g_strdup_printf("%s.o", executable);
|
||||||
|
|
||||||
// check wether object file (file.o) exists
|
// check wether object file (file.o) exists
|
||||||
if (stat(object_file, &st) == 0)
|
if (g_stat(object_file, &st) == 0)
|
||||||
{ // check wether src is newer than object file
|
{ // check wether src is newer than object file
|
||||||
if (stat(locale_filename, &st2) == 0)
|
if (g_stat(locale_filename, &st2) == 0)
|
||||||
{
|
{
|
||||||
if (st2.st_mtime > st.st_mtime)
|
if (st2.st_mtime > st.st_mtime)
|
||||||
{
|
{
|
||||||
@ -546,7 +547,7 @@ static gchar *prepare_run_script(gint idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check whether executable exists
|
// check whether executable exists
|
||||||
if (stat(check_executable, &st) != 0)
|
if (g_stat(check_executable, &st) != 0)
|
||||||
{
|
{
|
||||||
utf8_check_executable = utils_get_utf8_from_locale(check_executable);
|
utf8_check_executable = utils_get_utf8_from_locale(check_executable);
|
||||||
msgwin_status_add(_("Failed to execute %s (make sure it is already built)"),
|
msgwin_status_add(_("Failed to execute %s (make sure it is already built)"),
|
||||||
|
|||||||
@ -39,6 +39,7 @@
|
|||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#include "dialogs.h"
|
#include "dialogs.h"
|
||||||
|
|
||||||
@ -674,8 +675,13 @@ void dialogs_show_file_properties(gint idx)
|
|||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H)
|
#if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H)
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
// don't try to convert the filename on Windows, it should be already in UTF8
|
||||||
|
locale_filename = g_strdup(doc_list[idx].file_name);
|
||||||
|
#else
|
||||||
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
||||||
if (stat(locale_filename, &st) == 0)
|
#endif
|
||||||
|
if (g_stat(locale_filename, &st) == 0)
|
||||||
{
|
{
|
||||||
// first copy the returned string and the trim it, to not modify the static glibc string
|
// first copy the returned string and the trim it, to not modify the static glibc string
|
||||||
// g_strchomp() is used to remove trailing EOL chars, which are there for whatever reason
|
// g_strchomp() is used to remove trailing EOL chars, which are there for whatever reason
|
||||||
|
|||||||
@ -48,6 +48,8 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <glib/gstdio.h>
|
||||||
|
|
||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "support.h"
|
#include "support.h"
|
||||||
#include "sciwrappers.h"
|
#include "sciwrappers.h"
|
||||||
@ -609,19 +611,16 @@ static gboolean load_text_file(const gchar *locale_filename, const gchar *utf8_f
|
|||||||
filedata->bom = FALSE;
|
filedata->bom = FALSE;
|
||||||
filedata->readonly = FALSE;
|
filedata->readonly = FALSE;
|
||||||
|
|
||||||
if (stat(locale_filename, &st) != 0)
|
if (g_stat(locale_filename, &st) != 0)
|
||||||
{
|
{
|
||||||
msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(errno));
|
msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(errno));
|
||||||
|
dialogs_show_msgbox(0, "%s %s", utf8_filename, locale_filename);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
filedata->mtime = st.st_mtime;
|
filedata->mtime = st.st_mtime;
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
|
||||||
if (! g_file_get_contents(utf8_filename, &filedata->data, NULL, &err))
|
|
||||||
#else
|
|
||||||
if (! g_file_get_contents(locale_filename, &filedata->data, NULL, &err))
|
if (! g_file_get_contents(locale_filename, &filedata->data, NULL, &err))
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
msgwin_status_add(err->message);
|
msgwin_status_add(err->message);
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
@ -742,7 +741,11 @@ gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean read
|
|||||||
|
|
||||||
// try to get the UTF-8 equivalent for the filename, fallback to filename if error
|
// try to get the UTF-8 equivalent for the filename, fallback to filename if error
|
||||||
locale_filename = g_strdup(filename);
|
locale_filename = g_strdup(filename);
|
||||||
|
#ifdef G_OS_WIN32 // on Win32 we only use locale_filename because it is already UTF8. I hope
|
||||||
|
utf8_filename = g_strdup(locale_filename);
|
||||||
|
#else
|
||||||
utf8_filename = utils_get_utf8_from_locale(locale_filename);
|
utf8_filename = utils_get_utf8_from_locale(locale_filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
// if file is already open, switch to it and go
|
// if file is already open, switch to it and go
|
||||||
idx = document_find_by_filename(utf8_filename, FALSE);
|
idx = document_find_by_filename(utf8_filename, FALSE);
|
||||||
@ -913,9 +916,13 @@ static gboolean document_update_timestamp(gint idx)
|
|||||||
|
|
||||||
g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE);
|
g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE);
|
||||||
|
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
// don't try to convert the filename on Windows, it should be already in UTF8
|
||||||
|
locale_filename = g_strdup(doc_list[idx].file_name);
|
||||||
|
#else
|
||||||
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
||||||
|
#endif
|
||||||
if (stat(locale_filename, &st) != 0)
|
if (g_stat(locale_filename, &st) != 0)
|
||||||
{
|
{
|
||||||
msgwin_status_add(_("Could not open file %s (%s)"), doc_list[idx].file_name,
|
msgwin_status_add(_("Could not open file %s (%s)"), doc_list[idx].file_name,
|
||||||
g_strerror(errno));
|
g_strerror(errno));
|
||||||
|
|||||||
19
src/utils.c
19
src/utils.c
@ -332,8 +332,13 @@ gboolean utils_check_disk_status(gint idx, gboolean force)
|
|||||||
|
|
||||||
if (! force && doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE;
|
if (! force && doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE;
|
||||||
|
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
// don't try to convert the filename on Windows, it should be already in UTF8
|
||||||
|
locale_filename = g_strdup(doc_list[idx].file_name);
|
||||||
|
#else
|
||||||
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
||||||
if (stat(locale_filename, &st) != 0)
|
#endif
|
||||||
|
if (g_stat(locale_filename, &st) != 0)
|
||||||
{
|
{
|
||||||
// TODO: warn user file on disk is missing
|
// TODO: warn user file on disk is missing
|
||||||
}
|
}
|
||||||
@ -1432,17 +1437,29 @@ gboolean utils_wrap_string(gchar *string, gint wrapstart)
|
|||||||
|
|
||||||
gchar *utils_get_locale_from_utf8(const gchar *utf8_text)
|
gchar *utils_get_locale_from_utf8(const gchar *utf8_text)
|
||||||
{
|
{
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
// just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions
|
||||||
|
// which would result in wrongly converted strings
|
||||||
|
return g_strdup(utf8_text);
|
||||||
|
#else
|
||||||
gchar *locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL);
|
gchar *locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL);
|
||||||
if (locale_text == NULL) locale_text = g_strdup(utf8_text);
|
if (locale_text == NULL) locale_text = g_strdup(utf8_text);
|
||||||
return locale_text;
|
return locale_text;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gchar *utils_get_utf8_from_locale(const gchar *locale_text)
|
gchar *utils_get_utf8_from_locale(const gchar *locale_text)
|
||||||
{
|
{
|
||||||
|
#ifdef G_OS_WIN32
|
||||||
|
// just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions
|
||||||
|
// which would result in wrongly converted strings
|
||||||
|
return g_strdup(locale_text);
|
||||||
|
#else
|
||||||
gchar *utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL);
|
gchar *utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL);
|
||||||
if (utf8_text == NULL) utf8_text = g_strdup(locale_text);
|
if (utf8_text == NULL) utf8_text = g_strdup(locale_text);
|
||||||
return utf8_text;
|
return utf8_text;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user