mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
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.
This commit is contained in:
parent
6796398522
commit
4a964f2566
11
ChangeLog
11
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-28 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
|
||||
|
@ -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-28 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
|
||||
|
@ -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-28 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
Fix G_STMT_START / G_STMT_END on Solaris. (#321972,
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user