mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-24 11:54:01 +00:00
Added the Windows implementation of the "improved" random number generation.
This commit is contained in:
parent
432d6a3596
commit
bb924c0038
16
Makefile.in
16
Makefile.in
@ -107,6 +107,7 @@ endif
|
||||
|
||||
ifeq (1,$(MINGW))
|
||||
MMG_RESOURCES = src/mmg/mmg-resources.rc
|
||||
LIBRPCRT = -lrpcrt4
|
||||
endif
|
||||
|
||||
DEP_COMMON = src/common/libmtxcommon.$(LIBMTXCOMMONEXT)
|
||||
@ -319,7 +320,8 @@ libmtxcommon_OBJECTS := $(patsubst %.cpp,%.o,$(libmtxcommon_SOURCES))
|
||||
src/common/libmtxcommon.dll: $(libmtxcommon_OBJECTS)
|
||||
@echo ' LD/DLL ' $@
|
||||
$(Q)$(LINKSHARED) -Wl,--out-implib=$@.a -o $@ $(libmtxcommon_OBJECTS) \
|
||||
-liconv -lz $(COMPRESSION_LIBRARIES) -lmatroska -lebml -lexpat
|
||||
-liconv -lz $(COMPRESSION_LIBRARIES) -lmatroska -lebml \
|
||||
-lexpat -lrpcrt4
|
||||
|
||||
src/common/libmtxcommon.a: $(libmtxcommon_OBJECTS)
|
||||
@rm -f $@
|
||||
@ -369,7 +371,7 @@ mkvmerge_LDADD = -lmtxinput -lmtxoutput \
|
||||
-lmtxcommon -lmatroska -lebml \
|
||||
-lavi -lrmff -lmpegparser \
|
||||
$(FLAC_LIBS) -lvorbis -logg -lz $(COMPRESSION_LIBRARIES) \
|
||||
-lexpat $(ICONV_LIBS) $(LIBINTL_LIBS)
|
||||
-lexpat $(ICONV_LIBS) $(LIBINTL_LIBS) $(LIBRPCRT)
|
||||
|
||||
#
|
||||
# src/info
|
||||
@ -380,7 +382,7 @@ mkvinfo_OBJECTS := $(patsubst %.cpp,%.o,$(mkvinfo_SOURCES))
|
||||
mkvinfo_DEPENDENCIES += $(DEP_COMMON)
|
||||
mkvinfo_LDADD = -lmtxcommon -lmatroska -lebml \
|
||||
$(WXWINDOWS_LIBS) \
|
||||
$(ICONV_LIBS) $(LIBINTL_LIBS)
|
||||
$(ICONV_LIBS) $(LIBINTL_LIBS) $(LIBRPCRT)
|
||||
|
||||
#
|
||||
# src/extract
|
||||
@ -391,7 +393,7 @@ mkvextract_OBJECTS := $(patsubst %.cpp,%.o,$(mkvextract_SOURCES))
|
||||
mkvextract_DEPENDENCIES += $(DEP_COMMON) $(DEP_AVILIB) $(DEP_RMFF)
|
||||
mkvextract_LDADD = -lmtxcommon -lvorbis -logg -lavi -lmatroska -lebml -lrmff \
|
||||
$(ICONV_LIBS) $(LIBINTL_LIBS) -lexpat \
|
||||
-lz $(COMPRESSION_LIBRARIES)
|
||||
-lz $(COMPRESSION_LIBRARIES) $(LIBRPCRT)
|
||||
|
||||
#
|
||||
# src
|
||||
@ -400,7 +402,8 @@ mkvextract_LDADD = -lmtxcommon -lvorbis -logg -lavi -lmatroska -lebml -lrmff \
|
||||
base64tool_SOURCES = src/base64tool.cpp
|
||||
base64tool_OBJECTS := $(patsubst %.cpp,%.o,$(base64tool_SOURCES))
|
||||
base64tool_DEPENDENCIES += $(DEP_COMMON)
|
||||
base64tool_LDADD = -lmtxcommon $(ICONV_LIBS) $(LIBINTL_LIBS)
|
||||
base64tool_LDADD = -lmtxcommon $(ICONV_LIBS) $(LIBINTL_LIBS) \
|
||||
$(LIBRPCRT)
|
||||
|
||||
#
|
||||
# src/mmg
|
||||
@ -411,7 +414,8 @@ mmg_OBJECTS := $(patsubst %.cpp,%.o,$(mmg_SOURCES)) \
|
||||
$(patsubst %.rc,%.o,$(MMG_RESOURCES))
|
||||
mmg_DEPENDENCIES += $(DEP_COMMON)
|
||||
mmg_LDADD = -lmtxcommon -lmatroska -lebml -lexpat $(ICONV_LIBS) \
|
||||
$(WXWINDOWS_LIBS) $(LIBINTL_LIBS) $(MINGW_GUIAPP)
|
||||
$(WXWINDOWS_LIBS) $(LIBINTL_LIBS) $(MINGW_GUIAPP) \
|
||||
$(LIBRPCRT)
|
||||
|
||||
mkvmerge: src/mkvmerge@EXEEXT@
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
#if !defined(SYS_WINDOWS)
|
||||
# include <sys/time.h>
|
||||
# include <time.h>
|
||||
#else
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "mm_io.h"
|
||||
@ -25,9 +27,41 @@
|
||||
|
||||
#if defined(SYS_WINDOWS)
|
||||
|
||||
bool random_c::m_seeded = false;
|
||||
|
||||
void
|
||||
random_c::generate_bytes(void *destination,
|
||||
int num_bytes) {
|
||||
int i, num_left;
|
||||
|
||||
i = 0;
|
||||
while (num_bytes > 0) {
|
||||
UUID uuid;
|
||||
RPC_STATUS status;
|
||||
|
||||
status = UuidCreate(&uuid);
|
||||
if ((RPC_S_OK != status) && (RPC_S_UUID_LOCAL_ONLY != status)) {
|
||||
if (!m_seeded) {
|
||||
srand(GetTickCount());
|
||||
m_seeded = true;
|
||||
}
|
||||
|
||||
while (0 > num_bytes) {
|
||||
((unsigned char *)destination)[i + num_bytes] =
|
||||
(unsigned char)(256.0 * rand() / (RAND_MAX + 1.0));
|
||||
--num_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
num_left = num_bytes > 8 ? 8 : num_bytes;
|
||||
memcpy((unsigned char *)destination + i, &uuid.Data4, num_left);
|
||||
num_bytes -= num_left;
|
||||
i += num_left;
|
||||
}
|
||||
}
|
||||
|
||||
#else // defined(SYS_WINDOWS)
|
||||
|
||||
bool random_c::m_seeded = false;
|
||||
auto_ptr<mm_file_io_c> random_c::m_dev_urandom;
|
||||
bool random_c::m_tried_dev_urandom = false;
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
|
||||
class MTX_DLL_API random_c {
|
||||
private:
|
||||
#if !defined(SYS_WINDOWS)
|
||||
static bool m_seeded;
|
||||
|
||||
#if !defined(SYS_WINDOWS)
|
||||
static auto_ptr<mm_file_io_c> m_dev_urandom;
|
||||
static bool m_tried_dev_urandom;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user