Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-11-06 23:51:03 +0300
committerCorinna Vinschen <corinna@vinschen.de>2009-11-06 23:51:03 +0300
commitb36d8c46e57442ac4dfb62dd602a610df230ff0e (patch)
tree330bb4de3ad090bc8179688227d3d5b89a9704ec
parent38090b588c85f4d29f9b145d3e8a685c93fee579 (diff)
* globals.cc (ro_u_scr): New R/O unicode string.
(ro_u_sys): Ditto. * syscalls.cc (nt_path_has_suffix): Replace with ... (nt_path_has_executable_suffix): New function checking for explicit executable suffixes. (rename): Call nt_path_has_executable_suffix instead of nt_path_has_suffix. Check oldpath for nt_path_has_executable_suffix as well to set old_explicit_suffix.
-rw-r--r--winsup/cygwin/ChangeLog11
-rw-r--r--winsup/cygwin/globals.cc2
-rw-r--r--winsup/cygwin/syscalls.cc50
3 files changed, 43 insertions, 20 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 7621c548a..703a3ee14 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,16 @@
2009-11-06 Corinna Vinschen <corinna@vinschen.de>
+ * globals.cc (ro_u_scr): New R/O unicode string.
+ (ro_u_sys): Ditto.
+ * syscalls.cc (nt_path_has_suffix): Replace with ...
+ (nt_path_has_executable_suffix): New function checking for explicit
+ executable suffixes.
+ (rename): Call nt_path_has_executable_suffix instead of
+ nt_path_has_suffix. Check oldpath for nt_path_has_executable_suffix
+ as well to set old_explicit_suffix.
+
+2009-11-06 Corinna Vinschen <corinna@vinschen.de>
+
* shared.cc (inst_root_inited): New static bool variable.
(init_installation_root): Set inst_root_inited to true.
(memory_init): Print installation root debug output only if
diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc
index f30b6d02a..e742b964c 100644
--- a/winsup/cygwin/globals.cc
+++ b/winsup/cygwin/globals.cc
@@ -91,6 +91,8 @@ UNICODE_STRING _RDATA ro_u_empty = _ROU (L"");
UNICODE_STRING _RDATA ro_u_lnk = _ROU (L".lnk");
UNICODE_STRING _RDATA ro_u_exe = _ROU (L".exe");
UNICODE_STRING _RDATA ro_u_com = _ROU (L".com");
+UNICODE_STRING _RDATA ro_u_scr = _ROU (L".scr");
+UNICODE_STRING _RDATA ro_u_sys = _ROU (L".sys");
UNICODE_STRING _RDATA ro_u_proc = _ROU (L"proc");
UNICODE_STRING _RDATA ro_u_pmem = _ROU (L"\\device\\physicalmemory");
UNICODE_STRING _RDATA ro_u_natp = _ROU (L"\\??\\");
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index f2c646480..55415b631 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1643,27 +1643,36 @@ stop_transaction (NTSTATUS status, HANDLE old_trans, HANDLE trans)
return status;
}
-/* This function tests if a filename has *any* suffix. In order to
- make this quick and simple, we define a suffix as being not longer
- than 4 chars, plus the leading dot. */
+/* This function tests if a filename has one of the "approved" executable
+ suffix. This list is probably not complete... */
static inline bool
-nt_path_has_suffix (PUNICODE_STRING upath)
-{
+nt_path_has_executable_suffix (PUNICODE_STRING upath)
+{
+ const PUNICODE_STRING blessed_executable_suffixes[] =
+ {
+ &ro_u_com,
+ &ro_u_exe,
+ &ro_u_scr,
+ &ro_u_sys,
+ NULL
+ };
+
USHORT pos = upath->Length / sizeof (WCHAR);
- const PWCHAR path = upath->Buffer;
- USHORT upto;
+ PWCHAR path;
+ UNICODE_STRING usuf;
+ const PUNICODE_STRING *suf;
/* Too short for a native path? */
if (pos < 8)
return false;
- upto = pos - 5;
- while (--pos >= upto)
- {
- if (path[pos] == L'.')
- return true;
- if (path[pos] == L'\\')
- break;
- }
+ /* Assumption: All executable suffixes have a length of three. */
+ path = upath->Buffer + pos - 4;
+ if (*path != L'.')
+ return false;
+ RtlInitCountedUnicodeString (&usuf, path, 4 * sizeof (WCHAR));
+ for (suf = blessed_executable_suffixes; *suf; ++suf)
+ if (RtlEqualUnicodeString (&usuf, *suf, TRUE))
+ return true;
return false;
}
@@ -1755,9 +1764,10 @@ rename (const char *oldpath, const char *newpath)
set_errno (ENOTDIR);
goto out;
}
- if (oldpc.known_suffix
- && (ascii_strcasematch (oldpath + olen - 4, ".lnk")
- || ascii_strcasematch (oldpath + olen - 4, ".exe")))
+ if ((oldpc.known_suffix
+ && (ascii_strcasematch (oldpath + olen - 4, ".lnk")
+ || ascii_strcasematch (oldpath + olen - 4, ".exe")))
+ || nt_path_has_executable_suffix (oldpc.get_nt_native_path ()))
old_explicit_suffix = true;
nlen = strlen (newpath);
@@ -1865,7 +1875,7 @@ rename (const char *oldpath, const char *newpath)
&ro_u_lnk, TRUE))
rename_append_suffix (newpc, newpath, nlen, ".lnk");
else if (oldpc.is_binary () && !old_explicit_suffix
- && !nt_path_has_suffix (newpc.get_nt_native_path ()))
+ && !nt_path_has_executable_suffix (newpc.get_nt_native_path ()))
/* To rename an executable foo.exe to bar-without-suffix, the
.exe suffix must be given explicitly in oldpath. */
rename_append_suffix (newpc, newpath, nlen, ".exe");
@@ -1896,7 +1906,7 @@ rename (const char *oldpath, const char *newpath)
else if (oldpc.is_binary ())
{
/* Never append .exe suffix if file has any suffix already. */
- if (!nt_path_has_suffix (newpc.get_nt_native_path ()))
+ if (!nt_path_has_executable_suffix (newpc.get_nt_native_path ()))
{
rename_append_suffix (new2pc, newpath, nlen, ".exe");
removepc = &newpc;