aboutsummaryrefslogtreecommitdiffstats
path: root/src/emacs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emacs.c')
-rw-r--r--src/emacs.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/emacs.c b/src/emacs.c
index 512174d562e..acb4959bfea 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -204,6 +204,9 @@ HANDLE w32_daemon_event;
204char **initial_argv; 204char **initial_argv;
205int initial_argc; 205int initial_argc;
206 206
207/* The name of the working directory, or NULL if this info is unavailable. */
208char const *emacs_wd;
209
207static void sort_args (int argc, char **argv); 210static void sort_args (int argc, char **argv);
208static void syms_of_emacs (void); 211static void syms_of_emacs (void);
209 212
@@ -406,7 +409,7 @@ terminate_due_to_signal (int sig, int backtrace_limit)
406/* Code for dealing with Lisp access to the Unix command line. */ 409/* Code for dealing with Lisp access to the Unix command line. */
407 410
408static void 411static void
409init_cmdargs (int argc, char **argv, int skip_args, char *original_pwd) 412init_cmdargs (int argc, char **argv, int skip_args, char const *original_pwd)
410{ 413{
411 int i; 414 int i;
412 Lisp_Object name, dir, handler; 415 Lisp_Object name, dir, handler;
@@ -694,7 +697,7 @@ main (int argc, char **argv)
694 char *ch_to_dir = 0; 697 char *ch_to_dir = 0;
695 698
696 /* If we use --chdir, this records the original directory. */ 699 /* If we use --chdir, this records the original directory. */
697 char *original_pwd = 0; 700 char const *original_pwd = 0;
698 701
699 /* Record (approximately) where the stack begins. */ 702 /* Record (approximately) where the stack begins. */
700 stack_bottom = (char *) &stack_bottom_variable; 703 stack_bottom = (char *) &stack_bottom_variable;
@@ -794,6 +797,8 @@ main (int argc, char **argv)
794 exit (0); 797 exit (0);
795 } 798 }
796 799
800 emacs_wd = emacs_get_current_dir_name ();
801
797 if (argmatch (argv, argc, "-chdir", "--chdir", 4, &ch_to_dir, &skip_args)) 802 if (argmatch (argv, argc, "-chdir", "--chdir", 4, &ch_to_dir, &skip_args))
798 { 803 {
799#ifdef WINDOWSNT 804#ifdef WINDOWSNT
@@ -804,13 +809,14 @@ main (int argc, char **argv)
804 filename_from_ansi (ch_to_dir, newdir); 809 filename_from_ansi (ch_to_dir, newdir);
805 ch_to_dir = newdir; 810 ch_to_dir = newdir;
806#endif 811#endif
807 original_pwd = emacs_get_current_dir_name ();
808 if (chdir (ch_to_dir) != 0) 812 if (chdir (ch_to_dir) != 0)
809 { 813 {
810 fprintf (stderr, "%s: Can't chdir to %s: %s\n", 814 fprintf (stderr, "%s: Can't chdir to %s: %s\n",
811 argv[0], ch_to_dir, strerror (errno)); 815 argv[0], ch_to_dir, strerror (errno));
812 exit (1); 816 exit (1);
813 } 817 }
818 original_pwd = emacs_wd;
819 emacs_wd = emacs_get_current_dir_name ();
814 } 820 }
815 821
816#if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK) && !defined (CYGWIN) 822#if defined (HAVE_SETRLIMIT) && defined (RLIMIT_STACK) && !defined (CYGWIN)
@@ -1289,21 +1295,21 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1289 { 1295 {
1290#ifdef NS_IMPL_COCOA 1296#ifdef NS_IMPL_COCOA
1291 /* Started from GUI? */ 1297 /* Started from GUI? */
1292 /* FIXME: Do the right thing if getenv returns NULL, or if 1298 /* FIXME: Do the right thing if get_homedir returns "", or if
1293 chdir fails. */ 1299 chdir fails. */
1294 if (! inhibit_window_system && ! isatty (STDIN_FILENO) && ! ch_to_dir) 1300 if (! inhibit_window_system && ! isatty (STDIN_FILENO) && ! ch_to_dir)
1295 chdir (getenv ("HOME")); 1301 chdir (get_homedir ());
1296 if (skip_args < argc) 1302 if (skip_args < argc)
1297 { 1303 {
1298 if (!strncmp (argv[skip_args], "-psn", 4)) 1304 if (!strncmp (argv[skip_args], "-psn", 4))
1299 { 1305 {
1300 skip_args += 1; 1306 skip_args += 1;
1301 if (! ch_to_dir) chdir (getenv ("HOME")); 1307 if (! ch_to_dir) chdir (get_homedir ());
1302 } 1308 }
1303 else if (skip_args+1 < argc && !strncmp (argv[skip_args+1], "-psn", 4)) 1309 else if (skip_args+1 < argc && !strncmp (argv[skip_args+1], "-psn", 4))
1304 { 1310 {
1305 skip_args += 2; 1311 skip_args += 2;
1306 if (! ch_to_dir) chdir (getenv ("HOME")); 1312 if (! ch_to_dir) chdir (get_homedir ());
1307 } 1313 }
1308 } 1314 }
1309#endif /* COCOA */ 1315#endif /* COCOA */