mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-27 23:53:18 +02:00
commit bash-20080828 snapshot
This commit is contained in:
@@ -26,7 +26,8 @@ static SHELL_VAR *
|
||||
assign_mypid (
|
||||
SHELL_VAR *self,
|
||||
char *value,
|
||||
arrayind_t unused )
|
||||
arrayind_t unused,
|
||||
char *key )
|
||||
{
|
||||
return (self);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ enable_mypid_builtin(WORD_LIST *list)
|
||||
}
|
||||
|
||||
char const *enable_mypid_doc[] = {
|
||||
"Enable $MYPID.",
|
||||
"",
|
||||
"Enables use of the ${MYPID} dynamic variable. ",
|
||||
"It will yield the current pid of a subshell.",
|
||||
(char *)0
|
||||
|
||||
@@ -36,77 +36,6 @@
|
||||
return (x); \
|
||||
} while (0)
|
||||
|
||||
#if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
|
||||
static int
|
||||
fsleep(sec, usec)
|
||||
long sec, usec;
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = sec;
|
||||
tv.tv_usec = usec;
|
||||
|
||||
return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
|
||||
}
|
||||
#else /* !HAVE_TIMEVAL || !HAVE_SELECT */
|
||||
static int
|
||||
fsleep(sec, usec)
|
||||
long sec, usec;
|
||||
{
|
||||
if (usec >= 500000) /* round */
|
||||
sec++;
|
||||
return (sleep(sec));
|
||||
}
|
||||
#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */
|
||||
|
||||
/*
|
||||
* An incredibly simplistic floating point converter.
|
||||
*/
|
||||
static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
|
||||
|
||||
static int
|
||||
convert(s, sp, usp)
|
||||
char *s;
|
||||
long *sp, *usp;
|
||||
{
|
||||
int n;
|
||||
long sec, usec;
|
||||
char *p;
|
||||
|
||||
sec = usec = 0;
|
||||
|
||||
#define DECIMAL '.'
|
||||
|
||||
for (p = s; p && *p; p++) {
|
||||
if (*p == DECIMAL) /* decimal point */
|
||||
break;
|
||||
if (DIGIT(*p) == 0)
|
||||
RETURN(0);
|
||||
sec = (sec * 10) + (*p - '0');
|
||||
}
|
||||
|
||||
if (*p == 0)
|
||||
RETURN(1);
|
||||
|
||||
if (*p == DECIMAL)
|
||||
p++;
|
||||
|
||||
/* Look for up to six digits past a decimal point. */
|
||||
for (n = 0; n < 6 && p[n]; n++) {
|
||||
if (DIGIT(p[n]) == 0)
|
||||
RETURN(0);
|
||||
usec = (usec * 10) + (p[n] - '0');
|
||||
}
|
||||
|
||||
/* Now convert to millionths */
|
||||
usec *= multiplier[n];
|
||||
|
||||
if (n == 6 && p[6] >= '5' && p[6] <= '9')
|
||||
usec++; /* round up 1 */
|
||||
|
||||
RETURN(1);
|
||||
}
|
||||
|
||||
int
|
||||
sleep_builtin (list)
|
||||
WORD_LIST *list;
|
||||
@@ -123,7 +52,7 @@ WORD_LIST *list;
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (convert(list->word->word, &sec, &usec)) {
|
||||
if (uconvert(list->word->word, &sec, &usec)) {
|
||||
fsleep(sec, usec);
|
||||
return(EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -36,29 +36,6 @@
|
||||
return (x); \
|
||||
} while (0)
|
||||
|
||||
#if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
|
||||
static int
|
||||
fsleep(sec, usec)
|
||||
long sec, usec;
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
tv.tv_sec = sec;
|
||||
tv.tv_usec = usec;
|
||||
|
||||
return select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv);
|
||||
}
|
||||
#else /* !HAVE_TIMEVAL || !HAVE_SELECT */
|
||||
static int
|
||||
fsleep(sec, usec)
|
||||
long sec, usec;
|
||||
{
|
||||
if (usec >= 500000) /* round */
|
||||
sec++;
|
||||
return (sleep(sec));
|
||||
}
|
||||
#endif /* !HAVE_TIMEVAL || !HAVE_SELECT */
|
||||
|
||||
/*
|
||||
* An incredibly simplistic floating point converter.
|
||||
*/
|
||||
@@ -123,7 +100,7 @@ WORD_LIST *list;
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (convert(list->word->word, &sec, &usec)) {
|
||||
if (uconvert(list->word->word, &sec, &usec)) {
|
||||
fsleep(sec, usec);
|
||||
return(EXECUTION_SUCCESS);
|
||||
}
|
||||
@@ -133,6 +110,8 @@ WORD_LIST *list;
|
||||
}
|
||||
|
||||
static char *sleep_doc[] = {
|
||||
"Suspend execution for specified period.",
|
||||
""
|
||||
"sleep suspends execution for a minimum of SECONDS[.FRACTION] seconds.",
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user