even better: don't require 64-bit types at all

also, improve wording of Build.sh (passive terms)
This commit is contained in:
tg 2007-10-25 14:26:53 +00:00
parent bbbe959bf2
commit 13676f4914
3 changed files with 16 additions and 33 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $MirOS: src/bin/mksh/Build.sh,v 1.273 2007/10/25 14:18:55 tg Exp $
# $MirOS: src/bin/mksh/Build.sh,v 1.274 2007/10/25 14:26:52 tg Exp $
#-
# Environment used: CC CFLAGS CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NOPWNAM MKSH_NOVI
@ -912,22 +912,6 @@ ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be dec
EOF
CC=$save_CC
if test 10 = $HAVE_ARC4RANDOM$HAVE_STDINT_H; then
ac_testn uint64_t <<-'EOF'
#include <sys/types.h>
int main(void) { return ((int)(uint64_t)0); }
EOF
ac_testn u_int64_t '!' uint64_t 0 'if u_int64_t can be used instead' <<-'EOF'
#include <sys/types.h>
int main(void) { return ((int)(u_int64_t)0); }
EOF
if test 1 = $HAVE_U_INT64_T; then
CPPFLAGS="$CPPFLAGS -Duint64_t=u_int64_t"
HAVE_UINT64_T=1
fi
ac_cppflags UINT64_T
fi
#
# other checks
#

6
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.180 2007/10/25 14:18:56 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.181 2007/10/25 14:26:53 tg Exp $"
#define MKSH_VERSION "R32 2007/10/25"
#if HAVE_SYS_PARAM_H
@ -118,10 +118,6 @@ typedef int bool;
#define true 1
#endif
#if HAVE_ARC4RANDOM && !HAVE_STDINT_H && !HAVE_UINT64_T
typedef unsigned long long uint64_t;
#endif
/* extra macros */
#ifndef timerclear

25
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.47 2007/10/25 14:18:56 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.48 2007/10/25 14:26:53 tg Exp $");
/*
* Variables
@ -25,7 +25,7 @@ static void unsetspec(struct tbl *);
static struct tbl *arraysearch(struct tbl *, uint32_t);
static const char *array_index_calc(const char *, bool *, uint32_t *);
static int rnd_get(void);
static void rnd_set(long);
static void rnd_set(u_long);
/*
* create a new block for function calls and simple commands
@ -860,7 +860,7 @@ makenv(void)
* and writes to $RANDOM a cheap operation.
*/
#if HAVE_ARC4RANDOM
static uint64_t rnd_cache = 0;
static uint32_t rnd_cache[2];
static char rnd_lastflag = 2;
#endif
@ -877,19 +877,20 @@ rnd_get(void)
srand(arc4random() & 0x7FFF);
} else if (rnd_lastflag == 0) {
/* transition from 0: addrandom */
rnd_cache ^= rand();
rnd_cache[0] ^= rand();
rnd_cache[1] ^= rand();
}
rnd_lastflag = Flag(FARC4RANDOM);
}
if (Flag(FARC4RANDOM)) {
if (rnd_cache)
if (rnd_cache[0] || rnd_cache[1])
#if HAVE_ARC4RANDOM_PUSHB
rv = arc4random_pushb(&rnd_cache, sizeof (rnd_cache));
rv = arc4random_pushb(rnd_cache, sizeof (rnd_cache));
#else
arc4random_addrandom((void *)&rnd_cache,
arc4random_addrandom((void *)rnd_cache,
sizeof (rnd_cache));
#endif
rnd_cache = 0;
rnd_cache[0] = rnd_cache[1] = 0;
return ((
#if HAVE_ARC4RANDOM_PUSHB
rv ? rv :
@ -901,10 +902,11 @@ rnd_get(void)
}
static void
rnd_set(long newval)
rnd_set(u_long newval)
{
#if HAVE_ARC4RANDOM
rnd_cache ^= (((uint64_t)newval) << 15) | rand();
rnd_cache[0] ^= (newval << 15) | rand();
rnd_cache[1] ^= newval >> 17;
if (Flag(FARC4RANDOM) == 1)
return;
if (Flag(FARC4RANDOM) == 2)
@ -927,7 +929,8 @@ change_random(u_long newval)
#if HAVE_ARC4RANDOM
if (Flag(FARC4RANDOM)) {
rnd_cache ^= ((uint64_t)rand() << 45) ^ (uint64_t)newval;
rnd_cache[0] ^= (newval << 15) | rand();
rnd_cache[1] ^= newval >> 17;
return;
}
#endif