/* general.c -- Stuff that is used by all files. */
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2011 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#include "config.h"
#include "bashtypes.h"
-#ifndef _MINIX
+#if defined (HAVE_SYS_PARAM_H)
# include <sys/param.h>
#endif
#include "posixstat.h"
#include "shell.h"
#include "test.h"
+#include "trap.h"
#include <tilde/tilde.h>
if (result)
*result = 0;
+ if (string == 0)
+ return 0;
+
errno = 0;
value = strtoimax (string, &ep, 10);
if (errno || ep == string)
/* If *string is not '\0' but *ep is '\0' on return, the entire string
is valid. */
- if (string && *string && *ep == '\0')
+ if (*string && *ep == '\0')
{
if (result)
*result = value;
return;
tty_fd = open (tty, O_RDWR|O_NONBLOCK);
}
- close (tty_fd);
+ if (tty_fd >= 0)
+ close (tty_fd);
}
/* Return 1 if PATH1 and PATH2 are the same file. This is kind of
/* Return 1 if STRING is "." or "..", optionally followed by a directory
separator */
int
-dot_or_dotdot (string)
+path_dot_or_dotdot (string)
const char *string;
{
if (string == 0 || *string == '\0' || *string != '.')
*nbeg++ = '.';
nlen = nend - ntail;
- memcpy (nbeg, ntail, nlen);
+ memmove (nbeg, ntail, nlen);
nbeg[nlen] = '\0';
return name;
old_immed = interrupt_immediately;
old_term = terminate_immediately;
- interrupt_immediately = terminate_immediately = 1;
+ /* We want to be able to interrupt tilde expansion. Ordinarily, we can just
+ jump to top_level, but we don't want to run any trap commands in a signal
+ handler context. We might be able to get away with just checking for
+ things like SIGINT and SIGQUIT. */
+ if (any_signals_trapped () < 0)
+ interrupt_immediately = 1;
+ terminate_immediately = 1;
tilde_additional_prefixes = assign_p == 0 ? (char **)0
: (assign_p == 2 ? bash_tilde_prefixes2 : bash_tilde_prefixes);
r = (*s == '~') ? unquoted_tilde_word (s) : 1;
ret = r ? tilde_expand (s) : savestring (s);
+
interrupt_immediately = old_immed;
terminate_immediately = old_term;
+
+ QUIT;
+
return (ret);
}