diff options
| author | Paul Eggert | 2018-11-13 09:29:14 -0800 |
|---|---|---|
| committer | Paul Eggert | 2018-11-13 09:32:50 -0800 |
| commit | 900276502fbb4dcabdabc5d7d24b4bc5645f2cf3 (patch) | |
| tree | 4d6c17f5b3cea0f4d5dfbc7243eb6495269a7e56 /src/emacs.c | |
| parent | ce1fb157e840fd292c3db4632831c4514a663890 (diff) | |
| download | emacs-900276502fbb4dcabdabc5d7d24b4bc5645f2cf3.tar.gz emacs-900276502fbb4dcabdabc5d7d24b4bc5645f2cf3.zip | |
Act like POSIX sh if $HOME is relative
POSIX says sh ~/foo should act like $HOME/foo even if $HOME is
relative, so be consistent with that (Bug#33255).
* admin/merge-gnulib (GNULIB_MODULES): Add dosname.
* src/buffer.c (init_buffer): Use emacs_wd to get
initial working directory with slash appended if needed.
(default-directory): Say it must be absolute.
* src/emacs.c (emacs_wd): New global variable.
(init_cmdargs): Dir arg is now char const *.
(main): Set emacs_wd.
* src/emacs.c (main) [NS_IMPL_COCOA]:
* src/fileio.c (Fexpand_file_name):
Use get_homedir instead of egetenv ("HOME").
* src/fileio.c: Include dosname.h, for IS_ABSOLUTE_FILE_NAME.
(splice_dir_file, get_homedir): New functions.
* src/xrdb.c (gethomedir): Remove. All callers changed
to use get_homedir and splice_dir_file.
* test/src/fileio-tests.el (fileio-tests--relative-HOME): New test.
Diffstat (limited to 'src/emacs.c')
| -rw-r--r-- | src/emacs.c | 20 |
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; | |||
| 204 | char **initial_argv; | 204 | char **initial_argv; |
| 205 | int initial_argc; | 205 | int initial_argc; |
| 206 | 206 | ||
| 207 | /* The name of the working directory, or NULL if this info is unavailable. */ | ||
| 208 | char const *emacs_wd; | ||
| 209 | |||
| 207 | static void sort_args (int argc, char **argv); | 210 | static void sort_args (int argc, char **argv); |
| 208 | static void syms_of_emacs (void); | 211 | static 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 | ||
| 408 | static void | 411 | static void |
| 409 | init_cmdargs (int argc, char **argv, int skip_args, char *original_pwd) | 412 | init_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 */ |