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

wide_path.h « utils « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3194ecf97ff76874a2b561e80d1a76d0193df1ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 <stdlib.h>
#include <wchar.h>

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; }
};