-
Notifications
You must be signed in to change notification settings - Fork 0
/
currentdir.c
130 lines (100 loc) · 2.46 KB
/
currentdir.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// currentdir.c
//
// Time-stamp: <03/02/01 12:40:51 keuchel@lightning>
#include "celib.h"
#ifdef _MT
#include "cethread.h"
#endif
#ifndef _MT
static wchar_t _current_dirw[MAX_PATH] = L"\\";
static wchar_t _current_root_dirw[MAX_PATH] = L"\\";
#endif
#ifdef _MT
#define _CURRENTDIRW _getptd()->_tcurrent_dirw
#define _CURRENTROOTDIRW _getptd()->_tcurrent_root_dirw
#else
#define _CURRENTDIRW _current_dirw
#define _CURRENTROOTDIRW _current_root_dirw
#endif
DWORD
XCEGetCurrentDirectoryA(DWORD dwSize, char *buf)
{
DWORD dwLen;
wchar_t wbuf[MAX_PATH];
dwLen = XCEGetCurrentDirectoryW(sizeof(wbuf), wbuf);
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, dwSize, NULL, NULL);
return dwLen;
}
DWORD
XCEGetCurrentDirectoryW(DWORD dwSize, wchar_t *buf)
{
wcscpy(buf, _CURRENTDIRW);
return wcslen(buf);
}
BOOL
XCESetCurrentDirectoryA(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, dir, -1, wdir, COUNTOF(wdir));
return XCESetCurrentDirectoryW(wdir);
}
BOOL
XCESetCurrentDirectoryW(const wchar_t *wdir)
{
DWORD dwAttr;
wchar_t wtmp[MAX_PATH];
XCEFixPathW(wdir, wtmp);
if((dwAttr = GetFileAttributesW(wtmp)) == 0xFFFFFFFF)
{
errno =_winerror2errno(GetLastError());
return FALSE;
}
if((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
errno = ENOTDIR;
return FALSE;
}
wcscpy(_CURRENTDIRW, wtmp);
return TRUE;
}
DWORD
XCEGetCurrentRootDirectoryA(DWORD dwSize, char *buf)
{
DWORD dwLen;
wchar_t wbuf[MAX_PATH];
dwLen = XCEGetCurrentRootDirectoryW(sizeof(wbuf), wbuf);
WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buf, dwSize, NULL, NULL);
return dwLen;
}
DWORD
XCEGetCurrentRootDirectoryW(DWORD dwSize, wchar_t *buf)
{
wcscpy(buf, _CURRENTROOTDIRW);
return wcslen(buf);
}
BOOL
XCESetCurrentRootDirectoryA(const char *dir)
{
wchar_t wdir[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, dir, -1, wdir, COUNTOF(wdir));
return XCESetCurrentRootDirectoryW(wdir);
}
BOOL
XCESetCurrentRootDirectoryW(const wchar_t *wdir)
{
DWORD dwAttr;
wchar_t wtmp[MAX_PATH];
XCEFixPathW(wdir, wtmp);
if((dwAttr = GetFileAttributesW(wtmp)) == 0xFFFFFFFF)
{
errno =_winerror2errno(GetLastError());
return FALSE;
}
if((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
errno = ENOTDIR;
return FALSE;
}
wcscpy(_CURRENTROOTDIRW, wtmp);
return TRUE;
}