* 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 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
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)
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;
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;
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);
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;
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
}
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;
}
~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;}
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 */
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);