/* Initialize the codepage for file names, needed to decode
non-ASCII file names during startup. */
w32_init_file_name_codepage ();
+ /* Initialize the startup directory, needed for emacs_wd below. */
+ w32_init_current_directory ();
#endif
w32_init_main_thread ();
#endif
exit (1);
}
original_pwd = emacs_wd;
+#ifdef WINDOWSNT
+ /* Reinitialize Emacs's notion of the startup directory. */
+ w32_init_current_directory ();
+#endif
emacs_wd = emacs_get_current_dir_name ();
}
/* The directory where we started, in UTF-8. */
static char startup_dir[MAX_UTF8_PATH];
-/* Get the current working directory. */
+/* Get the current working directory. The caller must arrange for CWD
+ to be allocated with enough space to hold a 260-char directory name
+ in UTF-8. IOW, the space should be at least MAX_UTF8_PATH bytes. */
+static void
+w32_get_current_directory (char *cwd)
+{
+ /* FIXME: Do we need to resolve possible symlinks in startup_dir?
+ Does it matter anywhere in Emacs? */
+ if (w32_unicode_filenames)
+ {
+ wchar_t wstartup_dir[MAX_PATH];
+
+ if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
+ emacs_abort ();
+ filename_from_utf16 (wstartup_dir, cwd);
+ }
+ else
+ {
+ char astartup_dir[MAX_PATH];
+
+ if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
+ emacs_abort ();
+ filename_from_ansi (astartup_dir, cwd);
+ }
+}
+
+/* For external callers. Used by 'main' in emacs.c. */
+void
+w32_init_current_directory (void)
+{
+ w32_get_current_directory (startup_dir);
+}
+
+/* Return the original directory where Emacs started. */
char *
getcwd (char *dir, int dirsize)
{
}
/* Remember the initial working directory for getcwd. */
- /* FIXME: Do we need to resolve possible symlinks in startup_dir?
- Does it matter anywhere in Emacs? */
- if (w32_unicode_filenames)
- {
- wchar_t wstartup_dir[MAX_PATH];
-
- if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
- emacs_abort ();
- filename_from_utf16 (wstartup_dir, startup_dir);
- }
- else
- {
- char astartup_dir[MAX_PATH];
-
- if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
- emacs_abort ();
- filename_from_ansi (astartup_dir, startup_dir);
- }
+ w32_get_current_directory (startup_dir);
{
static char modname[MAX_PATH];
/* NULL for root_dir means use root from current directory. */
if (root_dir == NULL)
{
- if (w32_unicode_filenames)
- {
- wchar_t curdirw[MAX_PATH];
-
- if (GetCurrentDirectoryW (MAX_PATH, curdirw) == 0)
- return NULL;
- filename_from_utf16 (curdirw, default_root);
- }
- else
- {
- char curdira[MAX_PATH];
-
- if (GetCurrentDirectoryA (MAX_PATH, curdira) == 0)
- return NULL;
- filename_from_ansi (curdira, default_root);
- }
+ w32_get_current_directory (default_root);
parse_root (default_root, (const char **)&root_dir);
*root_dir = 0;
root_dir = default_root;