summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@novell.com>2005-12-01 04:02:40 +0000
committerTor Lillqvist <tml@src.gnome.org>2005-12-01 04:02:40 +0000
commit1b5d3fe981bdf96c0cdeb9d7ab3b53154c80fc6a (patch)
tree46c595289ae0cc5f50a2d895ab19e951e7d09612
parent1e2386e7d39cb2d11490d854693e965be09a9c3a (diff)
In the Win32 implementation, strip trailing slash(es) for non-root
2005-12-01 Tor Lillqvist <tml@novell.com> * glib/gstdio.c (g_stat): In the Win32 implementation, strip trailing slash(es) for non-root folders. stat() fails if non-root folders are specified with trailing slashes. It's too much hassle to demand that callers strip such slashes themselves, especially as it is easy to get it wrong and strip the slash of a root folder. (g_rename): On NT-based Windows, use MoveFileEx() with MOVEFILE_REPLACE_EXISTING to better match Unix behaviour.
-rw-r--r--ChangeLog11
-rw-r--r--ChangeLog.pre-2-1011
-rw-r--r--ChangeLog.pre-2-1211
-rw-r--r--glib/gstdio.c37
4 files changed, 68 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 310dc1a5e..4b94d48d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-12-01 Tor Lillqvist <tml@novell.com>
+
+ * glib/gstdio.c (g_stat): In the Win32 implementation, strip
+ trailing slash(es) for non-root folders. stat() fails if non-root
+ folders are specified with trailing slashes. It's too much hassle
+ to demand that callers strip such slashes themselves, especially
+ as it is easy to get it wrong and strip the slash of a root
+ folder.
+ (g_rename): On NT-based Windows, use MoveFileEx() with
+ MOVEFILE_REPLACE_EXISTING to better match Unix behaviour.
+
2005-11-27 Matthias Clasen <mclasen@redhat.com>
* glib/gunicollate.c (g_utf8_collate_key_for_filename):
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 310dc1a5e..4b94d48d2 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,14 @@
+2005-12-01 Tor Lillqvist <tml@novell.com>
+
+ * glib/gstdio.c (g_stat): In the Win32 implementation, strip
+ trailing slash(es) for non-root folders. stat() fails if non-root
+ folders are specified with trailing slashes. It's too much hassle
+ to demand that callers strip such slashes themselves, especially
+ as it is easy to get it wrong and strip the slash of a root
+ folder.
+ (g_rename): On NT-based Windows, use MoveFileEx() with
+ MOVEFILE_REPLACE_EXISTING to better match Unix behaviour.
+
2005-11-27 Matthias Clasen <mclasen@redhat.com>
* glib/gunicollate.c (g_utf8_collate_key_for_filename):
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 310dc1a5e..4b94d48d2 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,14 @@
+2005-12-01 Tor Lillqvist <tml@novell.com>
+
+ * glib/gstdio.c (g_stat): In the Win32 implementation, strip
+ trailing slash(es) for non-root folders. stat() fails if non-root
+ folders are specified with trailing slashes. It's too much hassle
+ to demand that callers strip such slashes themselves, especially
+ as it is easy to get it wrong and strip the slash of a root
+ folder.
+ (g_rename): On NT-based Windows, use MoveFileEx() with
+ MOVEFILE_REPLACE_EXISTING to better match Unix behaviour.
+
2005-11-27 Matthias Clasen <mclasen@redhat.com>
* glib/gunicollate.c (g_utf8_collate_key_for_filename):
diff --git a/glib/gstdio.c b/glib/gstdio.c
index 53cd135d5..c6cd7ba81 100644
--- a/glib/gstdio.c
+++ b/glib/gstdio.c
@@ -33,6 +33,7 @@
#endif
#ifdef G_OS_WIN32
+#include <windows.h>
#include <errno.h>
#include <wchar.h>
#include <direct.h>
@@ -372,8 +373,26 @@ g_rename (const gchar *oldfilename,
return -1;
}
- retval = _wrename (woldfilename, wnewfilename);
- save_errno = errno;
+ if (MoveFileExW (woldfilename, wnewfilename, MOVEFILE_REPLACE_EXISTING))
+ retval = 0;
+ else
+ {
+ retval = -1;
+ switch (GetLastError ())
+ {
+#define CASE(a,b) case ERROR_##a: save_errno = b; break
+ CASE (FILE_NOT_FOUND, ENOENT);
+ CASE (PATH_NOT_FOUND, ENOENT);
+ CASE (ACCESS_DENIED, EACCES);
+ CASE (NOT_SAME_DEVICE, EXDEV);
+ CASE (LOCK_VIOLATION, EACCES);
+ CASE (SHARING_VIOLATION, EACCES);
+ CASE (FILE_EXISTS, EEXIST);
+ CASE (ALREADY_EXISTS, EEXIST);
+#undef CASE
+ default: save_errno = EIO;
+ }
+ }
g_free (woldfilename);
g_free (wnewfilename);
@@ -570,6 +589,7 @@ g_stat (const gchar *filename,
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
+ int len;
if (wfilename == NULL)
{
@@ -577,6 +597,12 @@ g_stat (const gchar *filename,
return -1;
}
+ len = wcslen (wfilename);
+ while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
+ len--;
+ if (len > g_path_skip_root (filename) - filename)
+ wfilename[len] = '\0';
+
retval = _wstat (wfilename, (struct _stat *) buf);
save_errno = errno;
@@ -590,6 +616,7 @@ g_stat (const gchar *filename,
gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
+ int len;
if (cp_filename == NULL)
{
@@ -597,6 +624,12 @@ g_stat (const gchar *filename,
return -1;
}
+ len = strlen (cp_filename);
+ while (len > 0 && G_IS_DIR_SEPARATOR (cp_filename[len-1]))
+ len--;
+ if (len > g_path_skip_root (filename) - filename)
+ cp_filename[len] = '\0';
+
retval = stat (cp_filename, buf);
save_errno = errno;