+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-28 Matthias Clasen <mclasen@redhat.com>
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
+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-28 Matthias Clasen <mclasen@redhat.com>
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
+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-28 Matthias Clasen <mclasen@redhat.com>
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
#endif
#ifdef G_OS_WIN32
+#include <windows.h>
#include <errno.h>
#include <wchar.h>
#include <direct.h>
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);
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
+ int len;
if (wfilename == NULL)
{
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;
gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
+ int len;
if (cp_filename == NULL)
{
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;