summaryrefslogtreecommitdiff
path: root/builtins/evalstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtins/evalstring.c')
-rw-r--r--builtins/evalstring.c50
1 files changed, 12 insertions, 38 deletions
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 56d2e1bc..37516bb6 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -4,7 +4,7 @@
Bash is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 1, or (at your option) any later
+ Software Foundation; either version 2, or (at your option) any later
version.
Bash is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License along
with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+ Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
#include <config.h>
@@ -30,7 +30,7 @@
#include <errno.h>
-#include "../filecntl.h"
+#include "filecntl.h"
#include "../bashansi.h"
#include "../shell.h"
@@ -54,6 +54,7 @@ extern int errno;
#define IS_BUILTIN(s) (builtin_address_internal(s, 0) != (struct builtin *)NULL)
extern void run_trap_cleanup ();
+extern int zwrite ();
extern int interactive, interactive_shell;
extern int indirection_level, startup_state, subshell_environment;
@@ -94,7 +95,7 @@ parse_and_execute (string, from_file, flags)
char *from_file;
int flags;
{
- int code;
+ int code, x;
volatile int should_jump_to_top_level, last_result;
char *orig_string;
COMMAND *volatile command;
@@ -119,6 +120,12 @@ parse_and_execute (string, from_file, flags)
# endif /* BANG_HISTORY */
#endif /* HISTORY */
+ if (interactive_shell)
+ {
+ x = get_current_prompt_level ();
+ add_unwind_protect (set_current_prompt_level, x);
+ }
+
add_unwind_protect (pop_stream, (char *)NULL);
if (orig_string)
add_unwind_protect (xfree, orig_string);
@@ -282,36 +289,6 @@ parse_and_execute (string, from_file, flags)
return (last_result);
}
-/* Write NB bytes from BUF to file descriptor FD, retrying the write if
- it is interrupted. We retry three times if we get a zero-length
- write. Any other signal causes this function to return prematurely. */
-static int
-zwrite (fd, buf, nb)
- int fd;
- unsigned char *buf;
- int nb;
-{
- int n, i, nt;
-
- for (n = nb, nt = 0;;)
- {
- i = write (fd, buf, n);
- if (i > 0)
- {
- n -= i;
- if (n <= 0)
- return nb;
- }
- else if (i == 0)
- {
- if (++nt > 3)
- return (nb - n);
- }
- else if (errno != EINTR)
- return -1;
- }
-}
-
/* Handle a $( < file ) command substitution. This expands the filename,
returning errors as appropriate, then just cats the file to the standard
output. */
@@ -349,10 +326,7 @@ cat_file (r)
rval = 0;
while (1)
{
- /* Retry the reads on EINTR. Any other error causes a break from the
- loop. */
- while ((nr = read (fd, lbuf, sizeof(lbuf))) < 0 && errno == EINTR)
- ;
+ nr = zread (fd, lbuf, sizeof(lbuf));
if (nr == 0)
break;
else if (nr < 0)