diff options
Diffstat (limited to 'builtins/return.def')
-rw-r--r-- | builtins/return.def | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/builtins/return.def b/builtins/return.def index 8340a44..2ab01ef 100644 --- a/builtins/return.def +++ b/builtins/return.def @@ -29,11 +29,17 @@ Causes a function to exit with the return value specified by N. If N is omitted, the return status is that of the last command. $END +#include <config.h> + +#if defined (HAVE_UNISTD_H) +# include <unistd.h> +#endif + #include "../shell.h" +#include "common.h" extern int last_command_exit_value; extern int return_catch_flag, return_catch_value; -extern jmp_buf return_catch; /* If we are executing a user-defined function then exit with the value specified as an argument. if no argument is given, then the last @@ -42,16 +48,13 @@ int return_builtin (list) WORD_LIST *list; { - return_catch_value = get_numeric_arg (list); - - if (!list) - return_catch_value = last_command_exit_value; + return_catch_value = list ? get_numeric_arg (list) : last_command_exit_value; if (return_catch_flag) longjmp (return_catch, 1); else { - builtin_error ("Can only `return' from a function"); + builtin_error ("can only `return' from a function or sourced script"); return (EXECUTION_FAILURE); } } |