3636 *
3737 * ***** END LICENSE BLOCK ***** */
3838
39- #include " nsXPCOMGlue.h"
4039#include " nsXULAppAPI.h"
4140#ifdef XP_WIN
4241#include < windows.h>
4544
4645#include < stdio.h>
4746#include < stdarg.h>
48- #include < string.h>
4947
5048#include " plstr.h"
5149#include " prprf.h"
5654#include " nsStringGlue.h"
5755
5856#ifdef XP_WIN
57+ // we want to use the DLL blocklist if possible
58+ #define XRE_WANT_DLL_BLOCKLIST
5959// we want a wmain entry point
6060#include " nsWindowsWMain.cpp"
61- #define snprintf _snprintf
62- #define strcasecmp _stricmp
6361#endif
64- #include " BinaryPath.h"
65-
66- #include " nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
6762
6863static void Output (const char *fmt, ... )
6964{
@@ -90,12 +85,12 @@ static PRBool IsArg(const char* arg, const char* s)
9085 {
9186 if (*++arg == ' -' )
9287 ++arg;
93- return !strcasecmp (arg, s);
88+ return !PL_strcasecmp (arg, s);
9489 }
9590
9691#if defined(XP_WIN) || defined(XP_OS2)
9792 if (*arg == ' /' )
98- return !strcasecmp (++arg, s);
93+ return !PL_strcasecmp (++arg, s);
9994#endif
10095
10196 return PR_FALSE;
@@ -111,46 +106,22 @@ class ScopedLogging
111106 ~ScopedLogging () { NS_LogTerm(); }
112107};
113108
114- XRE_GetFileFromPathType XRE_GetFileFromPath;
115- XRE_CreateAppDataType XRE_CreateAppData;
116- XRE_FreeAppDataType XRE_FreeAppData;
117- #ifdef XRE_HAS_DLL_BLOCKLIST
118- XRE_SetupDllBlocklistType XRE_SetupDllBlocklist;
119- #endif
120- XRE_mainType XRE_main;
121-
122- static const nsDynamicFunctionLoad kXULFuncs [] = {
123- { " XRE_GetFileFromPath" , (NSFuncPtr*) &XRE_GetFileFromPath },
124- { " XRE_CreateAppData" , (NSFuncPtr*) &XRE_CreateAppData },
125- { " XRE_FreeAppData" , (NSFuncPtr*) &XRE_FreeAppData },
126- #ifdef XRE_HAS_DLL_BLOCKLIST
127- { " XRE_SetupDllBlocklist" , (NSFuncPtr*) &XRE_SetupDllBlocklist },
128- #endif
129- { " XRE_main" , (NSFuncPtr*) &XRE_main },
130- { nsnull, nsnull }
131- };
132-
133- static int do_main (const char *exePath, int argc, char * argv[])
109+ int main (int argc, char * argv[])
134110{
111+ ScopedLogging log;
112+
135113 nsCOMPtr<nsILocalFile> appini;
136- #ifdef XP_WIN
137- // exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8
138- // encoded path, so it is safe to convert it
139- nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE,
140- getter_AddRefs (appini));
141- #else
142- nsresult rv = NS_NewNativeLocalFile(nsDependentCString (exePath), PR_FALSE,
143- getter_AddRefs (appini));
144- #endif
114+ nsresult rv = XRE_GetBinaryPath (argv[0 ], getter_AddRefs (appini));
145115 if (NS_FAILED(rv)) {
116+ Output (" Couldn't calculate the application directory." );
146117 return 255 ;
147118 }
148-
149119 appini->SetNativeLeafName (NS_LITERAL_CSTRING(" application.ini" ));
150120
151121 // Allow firefox.exe to launch XULRunner apps via -app <application.ini>
152122 // Note that -app must be the *first* argument.
153- const char *appDataFile = getenv (" XUL_APP_FILE" );
123+ char *appEnv = nsnull;
124+ const char *appDataFile = PR_GetEnv (" XUL_APP_FILE" );
154125 if (appDataFile && *appDataFile) {
155126 rv = XRE_GetFileFromPath (appDataFile, getter_AddRefs (appini));
156127 if (NS_FAILED(rv)) {
@@ -170,12 +141,8 @@ static int do_main(const char *exePath, int argc, char* argv[])
170141 return 255 ;
171142 }
172143
173- char appEnv[MAXPATHLEN];
174- snprintf (appEnv, MAXPATHLEN, " XUL_APP_FILE=%s" , argv[2 ]);
175- if (putenv (appEnv)) {
176- Output (" Couldn't set %s.\n " , appEnv);
177- return 255 ;
178- }
144+ appEnv = PR_smprintf (" XUL_APP_FILE=%s" , argv[2 ]);
145+ PR_SetEnv (appEnv);
179146 argv[2 ] = argv[0 ];
180147 argv += 2 ;
181148 argc -= 2 ;
@@ -190,62 +157,7 @@ static int do_main(const char *exePath, int argc, char* argv[])
190157
191158 int result = XRE_main (argc, argv, appData);
192159 XRE_FreeAppData (appData);
193- return result;
194- }
195-
196- int main (int argc, char * argv[])
197- {
198- char exePath[MAXPATHLEN];
199-
200- nsresult rv = mozilla::BinaryPath::Get (argv[0 ], exePath);
201- if (NS_FAILED(rv)) {
202- Output (" Couldn't calculate the application directory.\n " );
203- return 255 ;
204- }
205-
206- char *lastSlash = strrchr (exePath, XPCOM_FILE_PATH_SEPARATOR[0 ]);
207- if (!lastSlash || (lastSlash - exePath > MAXPATHLEN - sizeof (XPCOM_DLL) - 1 ))
208- return 255 ;
209-
210- strcpy (++lastSlash, XPCOM_DLL);
211-
212- #ifdef XP_WIN
213- // GetProcessIoCounters().ReadOperationCount seems to have little to
214- // do with actual read operations. It reports 0 or 1 at this stage
215- // in the program. Luckily 1 coincides with when prefetch is
216- // enabled. If Windows prefetch didn't happen we can do our own
217- // faster dll preloading.
218- IO_COUNTERS ioCounters;
219- if (GetProcessIoCounters (GetCurrentProcess (), &ioCounters)
220- && !ioCounters.ReadOperationCount )
221- #endif
222- {
223- XPCOMGlueEnablePreload ();
224- }
225-
226-
227- rv = XPCOMGlueStartup (exePath);
228- if (NS_FAILED(rv)) {
229- Output (" Couldn't load XPCOM.\n " );
230- return 255 ;
231- }
232-
233- rv = XPCOMGlueLoadXULFunctions (kXULFuncs );
234- if (NS_FAILED(rv)) {
235- Output (" Couldn't load XRE functions.\n " );
236- return 255 ;
237- }
238-
239- #ifdef XRE_HAS_DLL_BLOCKLIST
240- XRE_SetupDllBlocklist ();
241- #endif
242-
243- int result;
244- {
245- ScopedLogging log;
246- result = do_main (exePath, argc, argv);
247- }
248-
249- XPCOMGlueShutdown ();
160+ if (appEnv)
161+ PR_smprintf_free (appEnv);
250162 return result;
251163}
0 commit comments