about summary refs log tree commit diff
path: root/Src/hist.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2020-03-21 18:01:36 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2020-03-25 23:49:01 +0000
commit38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878 (patch)
treec4053e7e8408fc45ed6f3f4a130cf93f63a79600 /Src/hist.c
parentde587b43ba10fc11159630fd63486e247ea8719c (diff)
downloadzsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.tar.gz
zsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.tar.xz
zsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.zip
45583/0002: chrealpath: Make symlink resolution optional.
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/Src/hist.c b/Src/hist.c
index 5281e8718..db2cc4ad7 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -842,7 +842,7 @@ histsubchar(int c)
 		break;
 
 	    case 'A':
-		if (!chrealpath(&sline)) {
+		if (!chrealpath(&sline, 'A')) {
 		    herrflush();
 		    zerr("modifier failed: A");
 		    return -1;
@@ -1922,9 +1922,18 @@ chabspath(char **junkptr)
     return 1;
 }
 
+/*
+ * Resolve symlinks in junkptr.
+ *
+ * If mode is 'A', resolve dot-dot before symlinks.  Else, mode should be 'P'.
+ * Refer to the documentation of the :A and :P modifiers for details.
+ *
+ * Return 0 for error, non-zero for success.
+ */
+
 /**/
 int
-chrealpath(char **junkptr)
+chrealpath(char **junkptr, char mode)
 {
     char *str;
 #ifdef HAVE_REALPATH
@@ -1936,12 +1945,14 @@ chrealpath(char **junkptr)
 # endif
 #endif
 
+    DPUTS1(mode != 'A' && mode != 'P', "chrealpath: mode='%c' is invalid", mode);
+
     if (!**junkptr)
 	return 1;
 
-    /* Notice that this means ..'s are applied before symlinks are resolved! */
-    if (!chabspath(junkptr))
-	return 0;
+    if (mode == 'A')
+	if (!chabspath(junkptr))
+	    return 0;
 
 #ifndef HAVE_REALPATH
     return 1;