From 26fb7ef5e4bb99f5766189c5edd722f093776aef Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 14 Mar 2009 14:56:20 +0000 Subject: * wide_path.h (class wide_path): New class to convert Windows path to WCHAR win32 path, including long path conversion if necessary. * cygcheck.cc: Use class wide_path throughout to call Win32 functions taking potentially long filenames. (display_error): Use snprintf rather than sprintf. (display_error_fmt): Ditto. (dump_sysinfo): Use FindFirstFileW/FindNextFileW. * cygpath.cc: Use class wide_path throughout to call Win32 functions taking potentially long filenames. (get_device_name): Raise buffer size to take long pathnames. (get_short_paths): Convert to using GetShortPathNameW. (get_short_name): Ditto. (get_long_path_name_w32impl): Convert to equivalent of GetLongPathNameW. (get_long_name): Convert to using GetLongPathNameW. (do_sysfolders): Raise buffer size for POSIX pathname to PATH_MAX. (do_pathconv): In case of POSIX->Win32 conversion, convert to wchar_t Win32 path name and drop long pathname prefix if possible. (main): Call setlocale to accommodate wide char/multibyte conversions. --- winsup/utils/wide_path.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 winsup/utils/wide_path.h (limited to 'winsup/utils/wide_path.h') diff --git a/winsup/utils/wide_path.h b/winsup/utils/wide_path.h new file mode 100644 index 000000000..8c49c5bf8 --- /dev/null +++ b/winsup/utils/wide_path.h @@ -0,0 +1,43 @@ +/* wide_path.h -- Define class wide_path to convert multibyte win32 path + to wchar_t Win32 path including long path prefix if + necessary. + + Copyright 2009 Red Hat, Inc. + + This file is part of Cygwin. + + This software is a copyrighted work licensed under the terms of the + Cygwin license. Please consult the file "CYGWIN_LICENSE" for + details. */ + +#include +#include + +class wide_path +{ + wchar_t *wp; + +public: + wide_path () : wp (NULL) {} + wide_path (const char *mb_path) + { + int len = mbstowcs (NULL, mb_path, 0) + 1; + wp = (wchar_t *) malloc ((len + 6) * sizeof (wchar_t)); + wchar_t *wp_p = wp; + if (len >= MAX_PATH && strncmp (mb_path, "\\\\?\\", 4) != 0) + { + wcscpy (wp_p, L"\\\\?\\"); + wp_p += 4; + if (strncmp (mb_path, "\\\\", 2) == 0) + { + wcscpy (wp_p, L"UNC"); + wp_p += 3; + ++mb_path; + --len; + } + } + mbstowcs (wp_p, mb_path, len); + } + ~wide_path () { if (wp) free (wp); } + operator const wchar_t *() const { return wp; } +}; -- cgit v1.2.3