[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: gaf.git: branch: master updated (1.5.0-20080706-291-gb6f3379)
The branch, master has been updated
via b6f3379b8144b72492e3a9922939ba99ab4d4480 (commit)
from 811233695be6f5d58ba576054d9763be11c6aa4c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
=========
Summary
=========
libgeda/src/f_basic.c | 50 ++++++++++++++++++++++++++++++++++++++----------
1 files changed, 39 insertions(+), 11 deletions(-)
=================
Commit Messages
=================
commit b6f3379b8144b72492e3a9922939ba99ab4d4480
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date: Sun Nov 2 19:47:37 2008 +0000
libgeda: Attempt to fix f_nomalize_filename for win32 systems
Patrick's re-written code for this made the assumption that the
root portion of an absolute path in windows is 3 characters long,
e.g. C:\. This is an invalid assumption to make.
Unfortunatey, g_path_is_absolute() regards paths such as \foo as
absolute, from which our code then assumed it could strip off the
first 3 characters. There are also UNC paths such as \\server\share\
where the root portion is an arbitrary length, which would not be
handled correctly.
g_path_skip_root() is aware of these details, and could be used to
pick out the root portion of a path accurately, but it doesn't help
in all cases. We could use it to determine that we need to add a
current drive-letter to a "semi-absolute" path without one, however
there is also the case with a path such as "C:foo", where we would
need to insert the CWD from a particular drive.
Path -> Root
---- ----
\\srv\share\foo -> \\serv\bar\ (fine, path is absolute)
C:\foo -> C:\ (fine, path is absolute)
C:foo -> C: (?) (needs current directory from drive C)
\foo -> \ (needs current working drive or UNC share)
foo -> (needs current working drive and directory)
Rather than trying to implement the logic to normalise paths on
Windows, conditionally compile in usage of the Win32 API function
GetFullPathName() when _WIN32 is defined. This implementation is
slightly modified from the Windows portion of libiberty's lrealpath
function. (GPL V2+).
f_normalize_filename() now differs slightly in its sematics on Win32,
as GetFullPathName() doesn't require or check that the file exists
on disk. We could add this feature if it turns out to be required.
:100644 100644 d5f976f... 643e91d... M libgeda/src/f_basic.c
=========
Changes
=========
commit b6f3379b8144b72492e3a9922939ba99ab4d4480
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date: Sun Nov 2 19:47:37 2008 +0000
libgeda: Attempt to fix f_nomalize_filename for win32 systems
Patrick's re-written code for this made the assumption that the
root portion of an absolute path in windows is 3 characters long,
e.g. C:\. This is an invalid assumption to make.
Unfortunatey, g_path_is_absolute() regards paths such as \foo as
absolute, from which our code then assumed it could strip off the
first 3 characters. There are also UNC paths such as \\server\share\
where the root portion is an arbitrary length, which would not be
handled correctly.
g_path_skip_root() is aware of these details, and could be used to
pick out the root portion of a path accurately, but it doesn't help
in all cases. We could use it to determine that we need to add a
current drive-letter to a "semi-absolute" path without one, however
there is also the case with a path such as "C:foo", where we would
need to insert the CWD from a particular drive.
Path -> Root
---- ----
\\srv\share\foo -> \\serv\bar\ (fine, path is absolute)
C:\foo -> C:\ (fine, path is absolute)
C:foo -> C: (?) (needs current directory from drive C)
\foo -> \ (needs current working drive or UNC share)
foo -> (needs current working drive and directory)
Rather than trying to implement the logic to normalise paths on
Windows, conditionally compile in usage of the Win32 API function
GetFullPathName() when _WIN32 is defined. This implementation is
slightly modified from the Windows portion of libiberty's lrealpath
function. (GPL V2+).
f_normalize_filename() now differs slightly in its sematics on Win32,
as GetFullPathName() doesn't require or check that the file exists
on disk. We could add this feature if it turns out to be required.
diff --git a/libgeda/src/f_basic.c b/libgeda/src/f_basic.c
index d5f976f..643e91d 100644
--- a/libgeda/src/f_basic.c
+++ b/libgeda/src/f_basic.c
@@ -44,6 +44,11 @@
#include <string.h>
#endif
+# if defined (_WIN32)
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h> /* for GetFullPathName */
+# endif
+
#include "libgeda_priv.h"
#ifdef HAVE_LIBDMALLOC
@@ -497,14 +502,13 @@ int f_save(TOPLEVEL *toplevel, const char *filename)
*/
gchar *f_normalize_filename (const gchar *name, GError **error)
{
-#ifdef G_OS_WIN32
-#define ROOT_MARKER_LEN 3
+#if defined (_WIN32)
+ char buf[MAX_PATH];
#else
-#define ROOT_MARKER_LEN 1
-#endif /* G_OS_WIN32 */
- GString *rpath;
- const char *start, *end;
-
+ GString *rpath;
+ const char *start, *end;
+#endif
+
if (name == NULL) {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL,
"%s", g_strerror (EINVAL));
@@ -517,8 +521,31 @@ gchar *f_normalize_filename (const gchar *name, GError **error)
return NULL;
}
+#if defined (_WIN32)
+ /* Windows method (modified) from libiberty's lrealpath.c, GPL V2+
+ *
+ * We assume we don't have symlinks and just canonicalize to a
+ * Windows absolute path. GetFullPathName converts ../ and ./ in
+ * relative paths to absolute paths, filling in current drive if
+ * one is not given or using the current directory of a specified
+ * drive (eg, "E:foo"). It also converts all forward slashes to
+ * back slashes.
+ */
+ DWORD len = GetFullPathName (name, MAX_PATH, buf, NULL);
+ if (len == 0 || len > MAX_PATH - 1) {
+ return g_strdup (name);
+ } else {
+ /* The file system is case-preserving but case-insensitive,
+ * canonicalize to lowercase, using the codepage associated
+ * with the process locale. */
+ CharLowerBuff (buf, len);
+ return g_strdup (buf);
+ }
+#else
+#define ROOT_MARKER_LEN 1
+
rpath = g_string_sized_new (strlen (name));
-
+
/* if relative path, prepend current dir */
if (!g_path_is_absolute (name)) {
gchar *cwd = g_get_current_dir ();
@@ -572,18 +599,19 @@ gchar *f_normalize_filename (const gchar *name, GError **error)
}
}
}
-
+
if (G_IS_DIR_SEPARATOR (rpath->str[rpath->len - 1]) &&
rpath->len > ROOT_MARKER_LEN) {
g_string_set_size (rpath, rpath->len - 1);
}
-
+
return g_string_free (rpath, FALSE);
- error:
+error:
g_string_free (rpath, TRUE);
return NULL;
#undef ROOT_MARKER_LEN
+#endif
}
/*! \brief Follow symlinks until a real file is found
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs