1This file is return.def, from which is created return.c.
2It implements the builtin "return" in Bash.
3
4Copyright (C) 1987-2003 Free Software Foundation, Inc.
5
6This file is part of GNU Bash, the Bourne Again SHell.
7
8Bash is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 2, or (at your option) any later
11version.
12
13Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License along
19with Bash; see the file COPYING.  If not, write to the Free Software
20Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
21
22$PRODUCES return.c
23
24$BUILTIN return
25
26$FUNCTION return_builtin
27$SHORT_DOC return [n]
28Causes a function to exit with the return value specified by N.  If N
29is omitted, the return status is that of the last command.
30$END
31
32#include <config.h>
33
34#if defined (HAVE_UNISTD_H)
35#  ifdef _MINIX
36#    include <sys/types.h>
37#  endif
38#  include <unistd.h>
39#endif
40
41#include "../bashintl.h"
42
43#include "../shell.h"
44#include "common.h"
45
46extern int last_command_exit_value;
47extern int subshell_environment;
48extern int return_catch_flag, return_catch_value;
49
50/* If we are executing a user-defined function then exit with the value
51   specified as an argument.  if no argument is given, then the last
52   exit status is used. */
53int
54return_builtin (list)
55     WORD_LIST *list;
56{
57  return_catch_value = get_exitstat (list);
58
59  if (return_catch_flag)
60    longjmp (return_catch, 1);
61  else
62    {
63      builtin_error (_("can only `return' from a function or sourced script"));
64      return (EXECUTION_FAILURE);
65    }
66}
67