aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1992-11-16 00:42:52 +0000
committerJim Blandy1992-11-16 00:42:52 +0000
commitc77d647ec8d6231214e952aeb216190e0cd42266 (patch)
tree1a40c11d0d0b5e7f0aedd568e3ebfad4fcca695e /src
parentb5c685f40245145a53adb441026f20c18ca2e289 (diff)
downloademacs-c77d647ec8d6231214e952aeb216190e0cd42266.tar.gz
emacs-c77d647ec8d6231214e952aeb216190e0cd42266.zip
* fileio.c (Fexpand_file_name): Don't fiddle with "/." if it's the
entire string.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c100
1 files changed, 61 insertions, 39 deletions
diff --git a/src/fileio.c b/src/fileio.c
index eb123de5630..58b7972a757 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -607,6 +607,11 @@ See also the function `substitute-in-file-name'.")
607 lose = 0; 607 lose = 0;
608 while (*p) 608 while (*p)
609 { 609 {
610 /* Since we know the path is absolute, we can assume that each
611 element starts with a "/". */
612
613 /* "//" anywhere isn't necessarily hairy; we just start afresh
614 with the second slash. */
610 if (p[0] == '/' && p[1] == '/' 615 if (p[0] == '/' && p[1] == '/'
611#ifdef APOLLO 616#ifdef APOLLO
612 /* // at start of filename is meaningful on Apollo system */ 617 /* // at start of filename is meaningful on Apollo system */
@@ -614,11 +619,18 @@ See also the function `substitute-in-file-name'.")
614#endif /* APOLLO */ 619#endif /* APOLLO */
615 ) 620 )
616 nm = p + 1; 621 nm = p + 1;
622
623 /* "~" is hairy as the start of any path element. */
617 if (p[0] == '/' && p[1] == '~') 624 if (p[0] == '/' && p[1] == '~')
618 nm = p + 1, lose = 1; 625 nm = p + 1, lose = 1;
619 if (p[0] == '/' && p[1] == '.' 626
620 && (p[2] == '/' || p[2] == 0 627 /* "." and ".." are hairy. */
621 || (p[2] == '.' && (p[3] == '/' || p[3] == 0)))) 628 if (p[0] == '/'
629 && p[1] == '.'
630 && (p[2] == '/'
631 || p[2] == 0
632 || (p[2] == '.' && (p[3] == '/'
633 || p[3] == 0))))
622 lose = 1; 634 lose = 1;
623#ifdef VMS 635#ifdef VMS
624 if (p[0] == '\\') 636 if (p[0] == '\\')
@@ -712,44 +724,46 @@ See also the function `substitute-in-file-name'.")
712 newdir = 0; 724 newdir = 0;
713 725
714 if (nm[0] == '~') /* prefix ~ */ 726 if (nm[0] == '~') /* prefix ~ */
715 if (nm[1] == '/' 727 {
728 if (nm[1] == '/'
716#ifdef VMS 729#ifdef VMS
717 || nm[1] == ':' 730 || nm[1] == ':'
718#endif /* VMS */ 731#endif /* VMS */
719 || nm[1] == 0)/* ~ by itself */ 732 || nm[1] == 0) /* ~ by itself */
720 { 733 {
721 if (!(newdir = (unsigned char *) egetenv ("HOME"))) 734 if (!(newdir = (unsigned char *) egetenv ("HOME")))
722 newdir = (unsigned char *) ""; 735 newdir = (unsigned char *) "";
723 nm++; 736 nm++;
724#ifdef VMS 737#ifdef VMS
725 nm++; /* Don't leave the slash in nm. */ 738 nm++; /* Don't leave the slash in nm. */
726#endif /* VMS */ 739#endif /* VMS */
727 } 740 }
728 else /* ~user/filename */ 741 else /* ~user/filename */
729 { 742 {
730 for (p = nm; *p && (*p != '/' 743 for (p = nm; *p && (*p != '/'
731#ifdef VMS 744#ifdef VMS
732 && *p != ':' 745 && *p != ':'
733#endif /* VMS */ 746#endif /* VMS */
734 ); p++); 747 ); p++);
735 o = (unsigned char *) alloca (p - nm + 1); 748 o = (unsigned char *) alloca (p - nm + 1);
736 bcopy ((char *) nm, o, p - nm); 749 bcopy ((char *) nm, o, p - nm);
737 o [p - nm] = 0; 750 o [p - nm] = 0;
738 751
739 pw = (struct passwd *) getpwnam (o + 1); 752 pw = (struct passwd *) getpwnam (o + 1);
740 if (pw) 753 if (pw)
741 { 754 {
742 newdir = (unsigned char *) pw -> pw_dir; 755 newdir = (unsigned char *) pw -> pw_dir;
743#ifdef VMS 756#ifdef VMS
744 nm = p + 1; /* skip the terminator */ 757 nm = p + 1; /* skip the terminator */
745#else 758#else
746 nm = p; 759 nm = p;
747#endif /* VMS */ 760#endif /* VMS */
748 } 761 }
749 762
750 /* If we don't find a user of that name, leave the name 763 /* If we don't find a user of that name, leave the name
751 unchanged; don't move nm forward to p. */ 764 unchanged; don't move nm forward to p. */
752 } 765 }
766 }
753 767
754 if (nm[0] != '/' 768 if (nm[0] != '/'
755#ifdef VMS 769#ifdef VMS
@@ -791,7 +805,7 @@ See also the function `substitute-in-file-name'.")
791 strcpy (target, newdir); 805 strcpy (target, newdir);
792 else 806 else
793#endif 807#endif
794 file_name_as_directory (target, newdir); 808 file_name_as_directory (target, newdir);
795 } 809 }
796 810
797 strcat (target, nm); 811 strcat (target, nm);
@@ -800,7 +814,7 @@ See also the function `substitute-in-file-name'.")
800 strcpy (target, sys_translate_unix (target)); 814 strcpy (target, sys_translate_unix (target));
801#endif /* VMS */ 815#endif /* VMS */
802 816
803 /* Now canonicalize by removing /. and /foo/.. if they appear */ 817 /* Now canonicalize by removing /. and /foo/.. if they appear. */
804 818
805 p = target; 819 p = target;
806 o = target; 820 o = target;
@@ -863,9 +877,17 @@ See also the function `substitute-in-file-name'.")
863 o = target; 877 o = target;
864 p++; 878 p++;
865 } 879 }
866 else if (p[0] == '/' && p[1] == '.' && 880 else if (p[0] == '/'
867 (p[2] == '/' || p[2] == 0)) 881 && p[1] == '.'
868 p += 2; 882 && (p[2] == '/'
883 || p[2] == 0))
884 {
885 /* If "/." is the entire filename, keep the "/". Otherwise,
886 just delete the whole "/.". */
887 if (o == target && p[2] == '\0')
888 *o++ = *p;
889 p += 2;
890 }
869 else if (!strncmp (p, "/..", 3) 891 else if (!strncmp (p, "/..", 3)
870 /* `/../' is the "superroot" on certain file systems. */ 892 /* `/../' is the "superroot" on certain file systems. */
871 && o != target 893 && o != target