1 /* -*- Mode: C; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is MOZCE Lib.
17 * The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
23 * John Wolfe <wolfe@lobo.us>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 #include "include/mozce_shunt.h"
41 #include "time_conversions.h"
45 // from environment.cpp
46 void putenv_copy(const char *k
, const char *v
);
48 ////////////////////////////////////////////////////////
49 // special folder stuff
50 ////////////////////////////////////////////////////////
52 typedef struct MOZCE_SHUNT_SPECIAL_FOLDER_INFO
56 } MozceShuntSpecialFolderInfo
;
58 // TAKEN DIRECTLY FROM MICROSOFT SHELLAPI.H HEADER FILE
59 // supported SHGetSpecialFolderPath nFolder ids
60 #define CSIDL_DESKTOP 0x0000
61 #define CSIDL_PROGRAMS 0x0002 // \Windows\Start Menu\Programs
62 #define CSIDL_PERSONAL 0x0005
63 #define CSIDL_WINDOWS 0x0024 // \Windows
64 #define CSIDL_PROGRAM_FILES 0x0026 // \Program Files
66 #define CSIDL_APPDATA 0x001A // NOT IN SHELLAPI.H header file
67 #define CSIDL_PROFILE 0x0028 // NOT IN SHELLAPI.H header file
69 MozceShuntSpecialFolderInfo mozceSpecialFoldersToEnvVars
[] = {
70 { CSIDL_APPDATA
, "APPDATA" },
71 { CSIDL_PROGRAM_FILES
, "ProgramFiles" },
72 { CSIDL_WINDOWS
, "windir" },
74 // { CSIDL_PROFILE, "HOMEPATH" }, // No return on WinMobile 6 Pro
75 // { CSIDL_PROFILE, "USERPROFILE" }, // No return on WinMobile 6 Pro
76 // { int, "ALLUSERSPROFILE" }, // Only one profile on WinCE
77 // { int, "CommonProgramFiles" },
78 // { int, "COMPUTERNAME" },
79 // { int, "HOMEDRIVE" },
80 // { int, "SystemDrive" },
81 // { int, "SystemRoot" },
87 static void InitializeSpecialFolderEnvVars()
89 MozceShuntSpecialFolderInfo
*p
= mozceSpecialFoldersToEnvVars
;
90 while ( p
&& p
->nFolder
&& p
->folderEnvName
) {
91 WCHAR wPath
[MAX_PATH
];
93 if ( SHGetSpecialFolderPath(NULL
, wPath
, p
->nFolder
, FALSE
) )
94 if ( 0 != WideCharToMultiByte(CP_ACP
, 0, wPath
, -1, cPath
, MAX_PATH
, 0, 0) )
95 putenv_copy(p
->folderEnvName
, cPath
);
100 ////////////////////////////////////////////////////////
102 ////////////////////////////////////////////////////////
104 char* strerror(int inErrno
)
106 return "Unknown Error";
112 ////////////////////////////////////////////////////////
114 ////////////////////////////////////////////////////////
116 wchar_t * _wgetcwd(wchar_t * dir
, unsigned long size
)
118 wchar_t tmp
[MAX_PATH
] = {0};
119 GetEnvironmentVariableW(L
"CWD", tmp
, size
);
121 if (wcslen(tmp
) > size
)
124 dir
= (wchar_t*)malloc(sizeof(wchar_t) * (wcslen(tmp
) + 2));
132 dir
= (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH
+ 1));
136 if (!GetModuleFileNameW(GetModuleHandle (NULL
), dir
, MAX_PATH
))
138 for (i
= wcslen(dir
); i
&& dir
[i
] != '\\'; i
--) {}
140 SetEnvironmentVariableW(L
"CWD", dir
);
142 size_t len
= wcslen(dir
);
143 if (dir
[len
- 1] != '\\' && (len
+ 2) < size
) {
150 wchar_t *_wfullpath( wchar_t *absPath
, const wchar_t *relPath
, unsigned long maxLength
)
153 absPath
= (wchar_t *)malloc(maxLength
*sizeof(wchar_t));
155 wchar_t cwd
[MAX_PATH
];
156 if (NULL
== _wgetcwd( cwd
, MAX_PATH
))
159 unsigned long len
= wcslen(cwd
);
160 if(!(cwd
[len
-1] == TCHAR('/') || cwd
[len
-1] == TCHAR('\\'))&& len
< maxLength
){
161 cwd
[len
] = TCHAR('\\');
162 cwd
[++len
] = TCHAR('\0');
164 if(len
+wcslen(relPath
) < maxLength
){
165 #if (_WIN32_WCE > 300)
166 if ( 0 < CeGetCanonicalPathName(relPath
[0] == L
'\\'? relPath
:
168 absPath
, maxLength
, 0))
171 #error Need CeGetCanonicalPathName to build.
172 // NO ACTUAL CeGetCanonicalPathName function in earlier versions of WinCE
178 int _wchdir(const WCHAR
* path
) {
179 return SetEnvironmentVariableW(L
"CWD", path
);
182 int _unlink(const char *filename
)
184 wchar_t wname
[MAX_PATH
];
186 MultiByteToWideChar(CP_ACP
,
192 return DeleteFileW(wname
)?0:-1;
200 TerminateProcess((HANDLE
) GetCurrentProcessId(), 3);
203 ////////////////////////////////////////////////////////
205 ////////////////////////////////////////////////////////
207 #define localeconv __not_supported_on_device_localeconv
212 struct lconv
* localeconv(void);
215 static struct lconv s_locale_conv
=
217 ".", /* decimal_point */
218 ",", /* thousands_sep */
219 "333", /* grouping */
220 "$", /* int_curr_symbol */
221 "$", /* currency_symbol */
222 "", /* mon_decimal_point */
223 "", /* mon_thousands_sep */
224 "", /* mon_grouping */
225 "+", /* positive_sign */
226 "-", /* negative_sign */
227 '2', /* int_frac_digits */
228 '2', /* frac_digits */
229 1, /* p_cs_precedes */
230 1, /* p_sep_by_space */
231 1, /* n_cs_precedes */
232 1, /* n_sep_by_space */
237 struct lconv
* localeconv(void)
239 return &s_locale_conv
;
243 ////////////////////////////////////////////////////////
245 ////////////////////////////////////////////////////////
247 BOOL WINAPI
DllMain(HANDLE hinstDLL
, DWORD fdwReason
, LPVOID lpReserved
)
249 // Perform actions based on the reason for calling.
252 case DLL_PROCESS_ATTACH
:
253 // Initialize once for each new process.
254 // Return FALSE to fail DLL load.
255 InitializeSpecialFolderEnvVars();
258 case DLL_THREAD_ATTACH
:
259 // Do thread-specific initialization.
262 case DLL_THREAD_DETACH
:
263 // Do thread-specific cleanup.
266 case DLL_PROCESS_DETACH
:
267 // Perform any necessary cleanup.
270 return TRUE
; // Successful DLL_PROCESS_ATTACH.