* Makefile.in (DLL_OFILES): Add newly-imported random.o. Eliminate reliance on
libiberty. * random.cc: Import from FreeBSD. Modify for Cygwin environment. * include/cygwin/stdlib.h (random): Reflect change in return value to be more linux/freebsd-like. (srandom): Ditto.
This commit is contained in:
parent
f3c7a5c457
commit
b85bae86cd
|
@ -1,3 +1,12 @@
|
||||||
|
2007-07-08 Christopher Faylor <me+cygwin@cgf.cx>
|
||||||
|
|
||||||
|
* Makefile.in (DLL_OFILES): Add newly-imported random.o. Eliminate
|
||||||
|
reliance on libiberty.
|
||||||
|
* random.cc: Import from FreeBSD. Modify for Cygwin environment.
|
||||||
|
* include/cygwin/stdlib.h (random): Reflect change in return value to
|
||||||
|
be more linux/freebsd-like.
|
||||||
|
(srandom): Ditto.
|
||||||
|
|
||||||
2007-07-07 Christopher Faylor <me+cygwin@cgf.cx>
|
2007-07-07 Christopher Faylor <me+cygwin@cgf.cx>
|
||||||
|
|
||||||
* fhandler.h (fhandler_base::write): Remove __stdcall decoration.
|
* fhandler.h (fhandler_base::write): Remove __stdcall decoration.
|
||||||
|
|
|
@ -115,9 +115,9 @@ LIBCOS:=${sort ${addsuffix .o,${basename ${notdir ${wildcard $(srcdir)/lib/*.c}}
|
||||||
|
|
||||||
EXTRA_DLL_OFILES:=${addsuffix .o,${basename ${notdir ${wildcard $(CONFIG_DIR)/*.c}}}}
|
EXTRA_DLL_OFILES:=${addsuffix .o,${basename ${notdir ${wildcard $(CONFIG_DIR)/*.c}}}}
|
||||||
|
|
||||||
EXTRA_OFILES=$(bupdir1)/libiberty/random.o
|
EXTRA_OFILES:=
|
||||||
|
|
||||||
MALLOC_OFILES=@MALLOC_OFILES@
|
MALLOC_OFILES:=@MALLOC_OFILES@
|
||||||
|
|
||||||
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libadvapi32.a $(w32api_lib)/libntdll.a
|
DLL_IMPORTS:=$(w32api_lib)/libkernel32.a $(w32api_lib)/libadvapi32.a $(w32api_lib)/libntdll.a
|
||||||
|
|
||||||
|
@ -137,14 +137,14 @@ DLL_OFILES:=assert.o autoload.o bsdlib.o ctype.o cxx.o cygheap.o cygthread.o \
|
||||||
grp.o heap.o hookapi.o inet_addr.o inet_network.o init.o ioctl.o ipc.o \
|
grp.o heap.o hookapi.o inet_addr.o inet_network.o init.o ioctl.o ipc.o \
|
||||||
localtime.o lsearch.o malloc_wrapper.o memmem.o minires-os-if.o \
|
localtime.o lsearch.o malloc_wrapper.o memmem.o minires-os-if.o \
|
||||||
minires.o miscfuncs.o mktemp.o mmap.o msg.o net.o netdb.o nftw.o \
|
minires.o miscfuncs.o mktemp.o mmap.o msg.o net.o netdb.o nftw.o \
|
||||||
passwd.o path.o pinfo.o pipe.o poll.o posix_ipc.o pthread.o regcomp.o \
|
passwd.o path.o pinfo.o pipe.o poll.o posix_ipc.o pthread.o random.o \
|
||||||
regerror.o regexec.o regfree.o registry.o resource.o rexec.o rcmd.o \
|
regcomp.o regerror.o regexec.o regfree.o registry.o resource.o rexec.o \
|
||||||
scandir.o sched.o sec_acl.o sec_helper.o security.o select.o sem.o \
|
rcmd.o scandir.o sched.o sec_acl.o sec_helper.o security.o select.o \
|
||||||
shared.o shm.o sigfe.o signal.o sigproc.o smallprint.o spawn.o strace.o \
|
sem.o shared.o shm.o sigfe.o signal.o sigproc.o smallprint.o spawn.o \
|
||||||
strptime.o strsep.o strsig.o sync.o syscalls.o sysconf.o syslog.o \
|
strace.o strptime.o strsep.o strsig.o sync.o syscalls.o sysconf.o \
|
||||||
termios.o thread.o timelocal.o timer.o times.o tty.o uinfo.o uname.o \
|
syslog.o termios.o thread.o timelocal.o timer.o times.o tty.o uinfo.o \
|
||||||
v8_regexp.o v8_regerror.o v8_regsub.o wait.o wincap.o window.o winf.o \
|
uname.o v8_regexp.o v8_regerror.o v8_regsub.o wait.o wincap.o window.o \
|
||||||
xsique.o \
|
winf.o xsique.o \
|
||||||
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
|
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
|
||||||
|
|
||||||
GMON_OFILES:=gmon.o mcount.o profil.o
|
GMON_OFILES:=gmon.o mcount.o profil.o
|
||||||
|
|
|
@ -24,8 +24,8 @@ void setprogname (const char *);
|
||||||
#ifndef __STRICT_ANSI__
|
#ifndef __STRICT_ANSI__
|
||||||
char *realpath (const char *, char *);
|
char *realpath (const char *, char *);
|
||||||
int unsetenv (const char *);
|
int unsetenv (const char *);
|
||||||
int random (void);
|
long random (void);
|
||||||
long srandom (unsigned);
|
void srandom (unsigned);
|
||||||
char *ptsname (int);
|
char *ptsname (int);
|
||||||
int grantpt (int);
|
int grantpt (int);
|
||||||
int unlockpt (int);
|
int unlockpt (int);
|
||||||
|
|
|
@ -27,20 +27,19 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
|
static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.25 2007/01/09 00:28:10 imp Exp $");
|
__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.25 2007/01/09 00:28:10 imp Exp $");
|
||||||
|
|
||||||
#include "namespace.h"
|
|
||||||
#include <sys/time.h> /* for srandomdev() */
|
#include <sys/time.h> /* for srandomdev() */
|
||||||
#include <fcntl.h> /* for srandomdev() */
|
#include <fcntl.h> /* for srandomdev() */
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h> /* for srandomdev() */
|
#include <unistd.h> /* for srandomdev() */
|
||||||
#include "un-namespace.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* random.c:
|
* random.c:
|
||||||
|
@ -216,10 +215,7 @@ static int rand_deg = DEG_3;
|
||||||
static int rand_sep = SEP_3;
|
static int rand_sep = SEP_3;
|
||||||
static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
|
static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
|
||||||
|
|
||||||
static inline uint32_t good_rand(int32_t);
|
static inline uint32_t good_rand (int32_t x)
|
||||||
|
|
||||||
static inline uint32_t good_rand (x)
|
|
||||||
int32_t x;
|
|
||||||
{
|
{
|
||||||
#ifdef USE_WEAK_SEEDING
|
#ifdef USE_WEAK_SEEDING
|
||||||
/*
|
/*
|
||||||
|
@ -264,8 +260,7 @@ static inline uint32_t good_rand (x)
|
||||||
* for default usage relies on values produced by this routine.
|
* for default usage relies on values produced by this routine.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
srandom(x)
|
srandom(unsigned x)
|
||||||
unsigned long x;
|
|
||||||
{
|
{
|
||||||
int i, lim;
|
int i, lim;
|
||||||
|
|
||||||
|
@ -283,6 +278,14 @@ srandom(x)
|
||||||
(void)random();
|
(void)random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Avoid a compiler warning when we really want to get at the junk in
|
||||||
|
an uninitialized variable. */
|
||||||
|
static unsigned long
|
||||||
|
dummy (unsigned long *x)
|
||||||
|
{
|
||||||
|
return *x;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* srandomdev:
|
* srandomdev:
|
||||||
*
|
*
|
||||||
|
@ -306,11 +309,11 @@ srandomdev()
|
||||||
len = rand_deg * sizeof state[0];
|
len = rand_deg * sizeof state[0];
|
||||||
|
|
||||||
done = 0;
|
done = 0;
|
||||||
fd = _open("/dev/random", O_RDONLY, 0);
|
fd = open("/dev/random", O_RDONLY, 0);
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
if (_read(fd, (void *) state, len) == (ssize_t) len)
|
if (read(fd, (void *) state, len) == (ssize_t) len)
|
||||||
done = 1;
|
done = 1;
|
||||||
_close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
|
@ -318,7 +321,7 @@ srandomdev()
|
||||||
unsigned long junk;
|
unsigned long junk;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk);
|
srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ dummy(&junk));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,10 +355,9 @@ srandomdev()
|
||||||
* complain about mis-alignment, but you should disregard these messages.
|
* complain about mis-alignment, but you should disregard these messages.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
initstate(seed, arg_state, n)
|
initstate(unsigned long seed, /* seed for R.N.G. */
|
||||||
unsigned long seed; /* seed for R.N.G. */
|
char *arg_state, /* pointer to state array */
|
||||||
char *arg_state; /* pointer to state array */
|
long n) /* # bytes of state info */
|
||||||
long n; /* # bytes of state info */
|
|
||||||
{
|
{
|
||||||
char *ostate = (char *)(&state[-1]);
|
char *ostate = (char *)(&state[-1]);
|
||||||
uint32_t *int_arg_state = (uint32_t *)arg_state;
|
uint32_t *int_arg_state = (uint32_t *)arg_state;
|
||||||
|
@ -420,8 +422,7 @@ initstate(seed, arg_state, n)
|
||||||
* complain about mis-alignment, but you should disregard these messages.
|
* complain about mis-alignment, but you should disregard these messages.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
setstate(arg_state)
|
setstate(char *arg_state /* pointer to state array */)
|
||||||
char *arg_state; /* pointer to state array */
|
|
||||||
{
|
{
|
||||||
uint32_t *new_state = (uint32_t *)arg_state;
|
uint32_t *new_state = (uint32_t *)arg_state;
|
||||||
uint32_t type = new_state[0] % MAX_TYPES;
|
uint32_t type = new_state[0] % MAX_TYPES;
|
||||||
|
@ -500,3 +501,4 @@ random()
|
||||||
}
|
}
|
||||||
return((long)i);
|
return((long)i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue