summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorPierre Humblet <phumblet@phumblet.no-ip.org>2004-06-17 13:34:26 +0000
committerPierre Humblet <phumblet@phumblet.no-ip.org>2004-06-17 13:34:26 +0000
commitbd0e9c7aa613edfdc3146014fb73c38df4748659 (patch)
tree31f22d9165d03ec109ea29e19480599e81b8abb5 /winsup/cygwin
parent9f35b464563d391929da0326ea37c15e6099cdce (diff)
downloadcygnal-bd0e9c7aa613edfdc3146014fb73c38df4748659.tar.gz
cygnal-bd0e9c7aa613edfdc3146014fb73c38df4748659.tar.bz2
cygnal-bd0e9c7aa613edfdc3146014fb73c38df4748659.zip
2004-06-17 Pierre Humblet <pierre.humblet@ieee.org>
* fhandler.cc (fhandler_base::open_9x): Do not check for null name. Move debug_printf to common code line. (fhandler_base::open): Ditto. Initialize upath. Remove second argument of pc.get_nt_native_path. * path.h (path_conv::get_nt_native_path): Remove second argument. * path.cc (path_conv::get_nt_native_path): Ditto. Call str2uni_cat. * security.h (str2buf2uni_cat): Delete declaration. (str2uni_cat): New declaration. * security.cc (str2buf2uni): Get length from sys_mbstowcs call. (str2buf2uni_cat): Delete function. (str2uni_cat): New function. * miscfuncs.cc (sys_mbstowcs): Add debug_printf.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog15
-rw-r--r--winsup/cygwin/fhandler.cc35
-rw-r--r--winsup/cygwin/miscfuncs.cc5
-rw-r--r--winsup/cygwin/path.cc16
-rw-r--r--winsup/cygwin/path.h2
-rw-r--r--winsup/cygwin/security.cc23
-rw-r--r--winsup/cygwin/security.h2
7 files changed, 55 insertions, 43 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 970deaa90..715b31ff4 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,18 @@
+2004-06-17 Pierre Humblet <pierre.humblet@ieee.org>
+
+ * fhandler.cc (fhandler_base::open_9x): Do not check for null name.
+ Move debug_printf to common code line.
+ (fhandler_base::open): Ditto. Initialize upath. Remove second argument
+ of pc.get_nt_native_path.
+ * path.h (path_conv::get_nt_native_path): Remove second argument.
+ * path.cc (path_conv::get_nt_native_path): Ditto. Call str2uni_cat.
+ * security.h (str2buf2uni_cat): Delete declaration.
+ (str2uni_cat): New declaration.
+ * security.cc (str2buf2uni): Get length from sys_mbstowcs call.
+ (str2buf2uni_cat): Delete function.
+ (str2uni_cat): New function.
+ * miscfuncs.cc (sys_mbstowcs): Add debug_printf.
+
2004-06-17 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::open): Substitute FILE_SUPERSEDE with
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 435eb983b..1ea719405 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -437,12 +437,6 @@ fhandler_base::open_9x (int flags, mode_t mode)
syscall_printf ("(%s, %p)", get_win32_name (), flags);
- if (get_win32_name () == NULL)
- {
- set_errno (ENOENT);
- goto done;
- }
-
if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_RDONLY)
access = GENERIC_READ;
else if ((flags & (O_RDONLY | O_WRONLY | O_RDWR)) == O_WRONLY)
@@ -512,16 +506,16 @@ fhandler_base::open_9x (int flags, mode_t mode)
goto done;
}
- syscall_printf ("%p = CreateFile (%s, %p, %p, %p, %p, %p, 0)",
- x, get_win32_name (), access, shared, &sa,
- creation_distribution, file_attributes);
-
set_io_handle (x);
set_flags (flags, pc.binmode ());
res = 1;
set_open_status ();
done:
+ debug_printf ("%p = CreateFile (%s, %p, %p, %p, %p, %p, 0)",
+ x, get_win32_name (), access, shared, &sa,
+ creation_distribution, file_attributes);
+
syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (),
flags);
return res;
@@ -534,11 +528,11 @@ fhandler_base::open (int flags, mode_t mode)
if (!wincap.is_winnt ())
return fhandler_base::open_9x (flags, mode);
- UNICODE_STRING upath;
WCHAR wpath[CYG_MAX_PATH + 10];
- pc.get_nt_native_path (upath, wpath);
+ UNICODE_STRING upath = {0, sizeof (wpath), wpath};
+ pc.get_nt_native_path (upath);
- if (RtlIsDosDeviceName_U (wpath))
+ if (RtlIsDosDeviceName_U (upath.Buffer))
return fhandler_base::open_9x (flags, mode);
int res = 0;
@@ -554,11 +548,6 @@ fhandler_base::open (int flags, mode_t mode)
NTSTATUS status;
syscall_printf ("(%s, %p)", get_win32_name (), flags);
- if (get_win32_name () == NULL)
- {
- set_errno (ENOENT);
- goto done;
- }
InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT,
sa.lpSecurityDescriptor, NULL);
@@ -657,17 +646,17 @@ fhandler_base::open (int flags, mode_t mode)
goto done;
}
- syscall_printf ("%x = NtCreateFile "
- "(%p, %x, %s, io, NULL, %x, %x, %x, %x, NULL, 0)",
- status, x, access, get_win32_name (), file_attributes, shared,
- create_disposition, create_options);
-
set_io_handle (x);
set_flags (flags, pc.binmode ());
res = 1;
set_open_status ();
done:
+ debug_printf ("%x = NtCreateFile "
+ "(%p, %x, %s, io, NULL, %x, %x, %x, %x, NULL, 0)",
+ status, x, access, get_win32_name (), file_attributes, shared,
+ create_disposition, create_options);
+
syscall_printf ("%d = fhandler_base::open (%s, %p)", res, get_win32_name (),
flags);
return res;
diff --git a/winsup/cygwin/miscfuncs.cc b/winsup/cygwin/miscfuncs.cc
index d36a824af..dcbe7c1b8 100644
--- a/winsup/cygwin/miscfuncs.cc
+++ b/winsup/cygwin/miscfuncs.cc
@@ -312,7 +312,10 @@ sys_wcstombs (char *tgt, const WCHAR *src, int len)
int __stdcall
sys_mbstowcs (WCHAR *tgt, const char *src, int len)
{
- return MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len);
+ int res = MultiByteToWideChar (get_cp (), 0, src, -1, tgt, len);
+ if (!res)
+ debug_printf ("MultiByteToWideChar %E");
+ return res;
}
extern "C" int
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 23bf2c207..c348268b6 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -459,25 +459,25 @@ path_conv::set_normalized_path (const char *path_copy)
}
PUNICODE_STRING
-path_conv::get_nt_native_path (UNICODE_STRING &upath, WCHAR *wpath)
+path_conv::get_nt_native_path (UNICODE_STRING &upath)
{
if (path[0] != '\\') /* X:\... or NUL, etc. */
{
- str2buf2uni (upath, wpath, "\\??\\");
- str2buf2uni_cat (upath, path);
+ str2uni_cat (upath, "\\??\\");
+ str2uni_cat (upath, path);
}
else if (path[1] != '\\') /* \Device\... */
- str2buf2uni (upath, wpath, path);
+ str2uni_cat (upath, path);
else if (path[2] != '.'
|| path[3] != '\\') /* \\server\share\... */
{
- str2buf2uni (upath, wpath, "\\??\\UNC\\");
- str2buf2uni_cat (upath, path + 2);
+ str2uni_cat (upath, "\\??\\UNC\\");
+ str2uni_cat (upath, path + 2);
}
else /* \\.\device */
{
- str2buf2uni (upath, wpath, "\\??\\");
- str2buf2uni_cat (upath, path + 4);
+ str2uni_cat (upath, "\\??\\");
+ str2uni_cat (upath, path + 4);
}
return &upath;
}
diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h
index 396749b0f..82e629dde 100644
--- a/winsup/cygwin/path.h
+++ b/winsup/cygwin/path.h
@@ -192,7 +192,7 @@ class path_conv
~path_conv ();
inline char *get_win32 () { return path; }
- PUNICODE_STRING get_nt_native_path (UNICODE_STRING &upath, WCHAR *wpath);
+ PUNICODE_STRING get_nt_native_path (UNICODE_STRING &upath);
operator char *() {return path;}
operator const char *() {return path;}
operator DWORD &() {return fileattr;}
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc
index 6ae52e9ff..c0ffadc00 100644
--- a/winsup/cygwin/security.cc
+++ b/winsup/cygwin/security.cc
@@ -156,23 +156,28 @@ str2buf2lsa (LSA_STRING &tgt, char *buf, const char *srcstr)
memcpy (buf, srcstr, tgt.MaximumLength);
}
+/* The dimension of buf is assumed to be at least strlen(srcstr) + 1,
+ The result will be shorter if the input has multibyte chars */
void
str2buf2uni (UNICODE_STRING &tgt, WCHAR *buf, const char *srcstr)
{
- tgt.Length = strlen (srcstr) * sizeof (WCHAR);
- tgt.MaximumLength = tgt.Length + sizeof (WCHAR);
tgt.Buffer = (PWCHAR) buf;
- sys_mbstowcs (buf, srcstr, tgt.MaximumLength);
+ tgt.MaximumLength = (strlen (srcstr) + 1) * sizeof (WCHAR);
+ tgt.Length = sys_mbstowcs (buf, srcstr, tgt.MaximumLength / sizeof (WCHAR))
+ * sizeof (WCHAR);
+ if (tgt.Length)
+ tgt.Length -= sizeof (WCHAR);
}
void
-str2buf2uni_cat (UNICODE_STRING &tgt, const char *srcstr)
+str2uni_cat (UNICODE_STRING &tgt, const char *srcstr)
{
- DWORD len = strlen (srcstr) * sizeof (WCHAR);
- sys_mbstowcs (tgt.Buffer + tgt.Length / sizeof (WCHAR), srcstr,
- len + tgt.MaximumLength);
- tgt.Length += len;
- tgt.MaximumLength += len;
+ int len = sys_mbstowcs (tgt.Buffer + tgt.Length / sizeof (WCHAR), srcstr,
+ (tgt.MaximumLength - tgt.Length) / sizeof (WCHAR));
+ if (len)
+ tgt.Length += (len - 1) * sizeof (WCHAR);
+ else
+ tgt.Length = tgt.MaximumLength = 0;
}
#if 0 /* unused */
diff --git a/winsup/cygwin/security.h b/winsup/cygwin/security.h
index b0bc6e414..77d913e81 100644
--- a/winsup/cygwin/security.h
+++ b/winsup/cygwin/security.h
@@ -276,7 +276,7 @@ int setacl (HANDLE, const char *, int, __acl32 *);
struct _UNICODE_STRING;
void __stdcall str2buf2uni (_UNICODE_STRING &, WCHAR *, const char *) __attribute__ ((regparm (3)));
-void __stdcall str2buf2uni_cat (_UNICODE_STRING &, const char *) __attribute__ ((regparm (2)));
+void __stdcall str2uni_cat (_UNICODE_STRING &, const char *) __attribute__ ((regparm (2)));
/* Try a subauthentication. */
HANDLE subauth (struct passwd *pw);