about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/mod_system.yo10
-rw-r--r--Src/Modules/system.c31
3 files changed, 47 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 77ab063ad..3b322ecd0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-02-25  Peter Stephenson  <pws@csr.com>
+
+	* 27755: Doc/Zsh/mod_system.yo, Src/Modules/system.c:
+	add "zsystem supports" to test what zsystem supports.
+
 2010-02-24  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* 27754: NEWS (unposted), Doc/Zsh/mod_system.yo, Src/exec.c,
@@ -12819,5 +12824,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4914 $
+* $Revision: 1.4915 $
 *****************************************************
diff --git a/Doc/Zsh/mod_system.yo b/Doc/Zsh/mod_system.yo
index 29047bfe4..dce07175f 100644
--- a/Doc/Zsh/mod_system.yo
+++ b/Doc/Zsh/mod_system.yo
@@ -148,6 +148,16 @@ If the option tt(-r) is given, the lock is only for reading, otherwise
 it is for reading and writing.  The file descriptor is opened
 accordingly.
 )
+item(tt(zsystem supports) var(subcommand))(
+The builtin tt(zsystem)'s subcommand tt(supports) tests whether a
+given subcommand is supported.  It returns status 0 if so, else
+status 1.  It operates silently unless there was a syntax error
+(i.e. the wrong number of arguments), in which case status 255
+is returned.  Status 1 can indicate one of two things:  var(subcommand)
+is known but not supported by the current operating system, or
+var(subcommand) is not known (possibly because this is an older
+version of the shell before it was implemented).
+)
 enditem()
 
 subsect(Parameters)
diff --git a/Src/Modules/system.c b/Src/Modules/system.c
index ef1ebb0b0..93796128b 100644
--- a/Src/Modules/system.c
+++ b/Src/Modules/system.c
@@ -491,6 +491,35 @@ bin_zsystem_flock(char *nam, char **args, UNUSED(Options ops), UNUSED(int func))
 }
 
 
+/*
+ * Return status zero if the zsystem feature is supported, else 1.
+ * Operates silently for future-proofing.
+ */
+/**/
+static int
+bin_zsystem_supports(char *nam, char **args,
+		     UNUSED(Options ops), UNUSED(int func))
+{
+    if (!args[0]) {
+	zwarnnam(nam, "supports: not enough arguments");
+	return 255;
+    }
+    if (args[1]) {
+	zwarnnam(nam, "supports: too many arguments");
+	return 255;
+    }
+
+    /* stupid but logically this should work... */
+    if (!strcmp(*args, "supports"))
+	return 0;
+#ifdef HAVE_FCNTL_H
+    if (!strcmp(*args, "flock"))
+	return 0;
+#endif
+    return 1;
+}
+
+
 /**/
 static int
 bin_zsystem(char *nam, char **args, Options ops, int func)
@@ -498,6 +527,8 @@ bin_zsystem(char *nam, char **args, Options ops, int func)
     /* If more commands are implemented, this can be more sophisticated */
     if (!strcmp(*args, "flock")) {
 	return bin_zsystem_flock(nam, args+1, ops, func);
+    } else if (!strcmp(*args, "supports")) {
+	return bin_zsystem_supports(nam, args+1, ops, func);
     }
     zwarnnam(nam, "unknown subcommand: %s", *args);
     return 1;