provide for Coherent not having gettimeofday(2), imake style (bad, but this is not for others to use without a second thought anyway)

This commit is contained in:
tg 2012-05-04 21:47:04 +00:00
parent 5488e79d3b
commit 7beac6668d
4 changed files with 21 additions and 12 deletions

10
funcs.c
View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.215 2012/05/04 21:15:32 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.216 2012/05/04 21:47:01 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -1884,7 +1884,7 @@ c_read(const char **wp)
#if HAVE_SELECT #if HAVE_SELECT
if (hastimeout) { if (hastimeout) {
gettimeofday(&tvlim, NULL); mksh_TIME(tvlim);
timeradd(&tvlim, &tv, &tvlim); timeradd(&tvlim, &tv, &tvlim);
} }
#endif #endif
@ -1896,7 +1896,7 @@ c_read(const char **wp)
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(fd, &fdset); FD_SET(fd, &fdset);
gettimeofday(&tv, NULL); mksh_TIME(tv);
timersub(&tvlim, &tv, &tv); timersub(&tvlim, &tv, &tv);
if (tv.tv_sec < 0) { if (tv.tv_sec < 0) {
/* timeout expired globally */ /* timeout expired globally */
@ -2504,7 +2504,7 @@ timex(struct op *t, int f, volatile int *xerrok)
struct rusage ru0, ru1, cru0, cru1; struct rusage ru0, ru1, cru0, cru1;
struct timeval usrtime, systime, tv0, tv1; struct timeval usrtime, systime, tv0, tv1;
gettimeofday(&tv0, NULL); mksh_TIME(tv0);
getrusage(RUSAGE_SELF, &ru0); getrusage(RUSAGE_SELF, &ru0);
getrusage(RUSAGE_CHILDREN, &cru0); getrusage(RUSAGE_CHILDREN, &cru0);
if (t->left) { if (t->left) {
@ -2521,7 +2521,7 @@ timex(struct op *t, int f, volatile int *xerrok)
rv = execute(t->left, f | XTIME, xerrok); rv = execute(t->left, f | XTIME, xerrok);
if (t->left->type == TCOM) if (t->left->type == TCOM)
tf |= t->left->str[0]; tf |= t->left->str[0];
gettimeofday(&tv1, NULL); mksh_TIME(tv1);
getrusage(RUSAGE_SELF, &ru1); getrusage(RUSAGE_SELF, &ru1);
getrusage(RUSAGE_CHILDREN, &cru1); getrusage(RUSAGE_CHILDREN, &cru1);
} else } else

6
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.218 2012/05/04 21:15:33 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.219 2012/05/04 21:47:02 tg Exp $");
extern char **environ; extern char **environ;
@ -135,7 +135,7 @@ rndsetup(void)
sigsetjmp(bufptr->jbuf, 1); sigsetjmp(bufptr->jbuf, 1);
#endif #endif
/* introduce variation (and yes, second arg MBZ for portability) */ /* introduce variation (and yes, second arg MBZ for portability) */
gettimeofday(&bufptr->tv, NULL); mksh_TIME(bufptr->tv);
NZATInit(h); NZATInit(h);
/* variation through pid, ppid, and the works */ /* variation through pid, ppid, and the works */
@ -1767,7 +1767,7 @@ DF(const char *fmt, ...)
struct timeval tv; struct timeval tv;
mksh_lockfd(shl_dbg_fd); mksh_lockfd(shl_dbg_fd);
gettimeofday(&tv, NULL); mksh_TIME(tv);
shf_fprintf(shl_dbg, "[%d.%06d:%d] ", (int)tv.tv_sec, (int)tv.tv_usec, shf_fprintf(shl_dbg, "[%d.%06d:%d] ", (int)tv.tv_sec, (int)tv.tv_usec,
(int)getpid()); (int)getpid());
va_start(args, fmt); va_start(args, fmt);

11
sh.h
View File

@ -152,7 +152,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.554 2012/05/04 21:15:34 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.555 2012/05/04 21:47:03 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/04/27" #define MKSH_VERSION "R40 2012/04/27"
@ -349,6 +349,15 @@ extern int __cdecl seteuid(uid_t);
extern int __cdecl setegid(gid_t); extern int __cdecl setegid(gid_t);
#endif #endif
#if defined(__COHERENT__)
#define mksh_TIME(tv) do { \
(tv).tv_usec = 0; \
(tv).tv_sec = time(NULL); \
} while (/* CONSTCOND */ 0)
#else
#define mksh_TIME(tv) gettimeofday(&(tv), NULL)
#endif
/* remove redundancies */ /* remove redundancies */
#if defined(MirBSD) && (MirBSD >= 0x08A8) && !defined(MKSH_OPTSTATIC) #if defined(MirBSD) && (MirBSD >= 0x08A8) && !defined(MKSH_OPTSTATIC)

6
var.c
View File

@ -27,7 +27,7 @@
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.147 2012/04/22 21:50:35 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.148 2012/05/04 21:47:04 tg Exp $");
/*- /*-
* Variables * Variables
@ -1088,7 +1088,7 @@ getspec(struct tbl *vp)
if (vp->flag & ISSET) { if (vp->flag & ISSET) {
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); mksh_TIME(tv);
i = tv.tv_sec - seconds; i = tv.tv_sec - seconds;
} else } else
return; return;
@ -1221,7 +1221,7 @@ setspec(struct tbl *vp)
{ {
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); mksh_TIME(tv);
seconds = tv.tv_sec - i; seconds = tv.tv_sec - i;
} }
break; break;