2009-03-14 22:56:20 +08:00
|
|
|
/* wide_path.h -- Define class wide_path to convert multibyte win32 path
|
2011-12-18 07:39:47 +08:00
|
|
|
to wchar_t Win32 path including long path prefix if
|
2009-03-14 22:56:20 +08:00
|
|
|
necessary.
|
|
|
|
|
2013-06-26 21:10:35 +08:00
|
|
|
Copyright 2009, 2011, 2013 Red Hat, Inc.
|
2009-03-14 22:56:20 +08:00
|
|
|
|
|
|
|
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 <stdlib.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
class wide_path
|
|
|
|
{
|
|
|
|
wchar_t *wp;
|
|
|
|
|
|
|
|
public:
|
|
|
|
wide_path () : wp (NULL) {}
|
2013-06-26 21:10:35 +08:00
|
|
|
wide_path (const char *mb_path, bool do_prefix = true)
|
2009-03-14 22:56:20 +08:00
|
|
|
{
|
|
|
|
int len = mbstowcs (NULL, mb_path, 0) + 1;
|
|
|
|
wp = (wchar_t *) malloc ((len + 6) * sizeof (wchar_t));
|
|
|
|
wchar_t *wp_p = wp;
|
2013-06-26 21:10:35 +08:00
|
|
|
if (do_prefix && len >= MAX_PATH && strncmp (mb_path, "\\\\?\\", 4) != 0)
|
2009-03-14 22:56:20 +08:00
|
|
|
{
|
|
|
|
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; }
|
|
|
|
};
|