Some compatibility fixes for legacy MinGW and Cygwin.

This commit is contained in:
LoRd_MuldeR 2020-10-21 17:07:03 +02:00
parent 1a31602d2a
commit 39d9aab439
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
5 changed files with 37 additions and 27 deletions

View File

@ -20,26 +20,25 @@ SUBDIR_LIB := libslunkcrypt
CFLAGS = -I$(SUBDIR_LIB)/include -Wall -Wno-trigraphs -march=$(MARCH) -mtune=$(MTUNE)
ifeq ($(DEBUG),1)
CFLAGS += -Og -g
CONFIG := _g
undefine LDFLGS
CFLAGS += -Og -g
LDFLGS :=
else
CONFIG :=
CFLAGS += -O3 -DNDEBUG
undefine CONFIG
LDFLGS += -static -s
endif
UNAME := $(shell uname)
MACHINE := $(shell $(CC) -dumpmachine)
undefine SUFFIX
ifneq ($(filter MINGW% CYGWIN%,$(UNAME)),)
ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
SUFFIX := .exe
else
undefine SUFFIX
SUFFIX :=
endif
ifneq ($(filter MINGW%,$(UNAME)),)
LDFLGS += -municode -mconsole
ifneq ($(filter %-w64-mingw32,$(MACHINE)),)
LDFLGS += -mconsole -municode
endif
# ---------------------------------------------------------------------------
@ -58,7 +57,7 @@ OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$
SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
ifneq ($(filter MINGW% CYGWIN%,$(UNAME)),)
ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
RCFILES_APP := $(wildcard $(SUBDIR_APP)/res/*.rc)
OBJECTS_APP += $(patsubst $(SUBDIR_APP)/res/%.rc,$(SUBDIR_APP)/obj/%.rsrc.o,$(RCFILES_APP))
endif

View File

@ -693,3 +693,14 @@ exiting:
return result;
}
#if defined(_WIN32) && defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
void __wgetmainargs(int*, wchar_t***, wchar_t***, int, int*);
int main()
{
wchar_t** enpv, ** argv;
int argc, si = 0;
__wgetmainargs(&argc, &argv, &enpv, 1, &si);
return wmain(argc, argv);
}
#endif

View File

@ -11,6 +11,9 @@
#include <string.h>
#ifdef _WIN32
#include <share.h>
#ifndef _SH_SECURE
#define _SH_SECURE 0x80
#endif
#endif
#ifdef _WIN32
@ -64,7 +67,7 @@
#define FPUTS(X,Y) fputws((X),(Y))
#define FPRINTF(X,Y,...) fwprintf((X),(Y),__VA_ARGS__)
#define FOPEN(X,Y) _wfsopen((X),(Y),_SH_SECURE)
#ifdef __MINGW32__
#ifdef __USE_MINGW_ANSI_STDIO
#define PRISTR "ls"
#define PRIstr "hs"
#define PRIwcs "ls"

View File

@ -11,6 +11,7 @@
#endif
#include "utils.h"
#include <slunkcrypt.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <signal.h>
@ -25,6 +26,9 @@
#define S_IFMT _S_IFMT
#define S_IFDIR _S_IFDIR
#define S_IFIFO _S_IFIFO
#ifndef _O_U8TEXT
#define _O_U8TEXT 0x40000
#endif
extern char *const _acmdln;
extern wchar_t *const _wcmdln;
#else
@ -44,8 +48,8 @@ void init_terminal(void)
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stderr), _O_U8TEXT);
if (_acmdln) SecureZeroMemory(_acmdln, strlen(_acmdln) * sizeof(char));
if (_wcmdln) SecureZeroMemory(_wcmdln, wcslen(_wcmdln) * sizeof(wchar_t));
if (_acmdln) slunkcrypt_bzero(_acmdln, strlen(_acmdln) * sizeof(char));
if (_wcmdln) slunkcrypt_bzero(_wcmdln, wcslen(_wcmdln) * sizeof(wchar_t));
#endif
}

View File

@ -4,6 +4,7 @@
/******************************************************************************/
#ifdef _WIN32
#define _WIN32_WINNT 0x0600
#define _CRT_RAND_S 1
#define WIN32_LEAN_AND_MEAN 1
#endif
@ -15,17 +16,9 @@
#else
#include <unistd.h>
#include <fcntl.h>
#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12))
#define HAVE_GENRANDOM_SYSCALL 1
#include <sys/random.h>
#else
#undef HAVE_GENRANDOM_SYSCALL
#endif
#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 11))
#define HAVE_EXPLICIT_BZERO 1
#include <string.h>
#else
#undef HAVE_EXPLICIT_BZERO
#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12))
#include <sys/random.h>
#endif
#endif
@ -50,7 +43,7 @@ int slunkcrypt_random_bytes(uint8_t* const buffer, const size_t length)
}
return 0;
#else
#ifdef HAVE_GENRANDOM_SYSCALL
#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12))
if (getrandom(buffer, length, 0U) >= length)
{
return 0;
@ -80,13 +73,13 @@ void slunkcrypt_bzero(void* const ptr, const size_t length)
{
if ((ptr) && (length > 0U))
{
#ifdef _WIN32
#if defined(_WIN32) && defined(SecureZeroMemory)
SecureZeroMemory(ptr, length);
#else
#ifdef HAVE_EXPLICIT_BZERO
#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 11))
explicit_bzero(ptr, length);
#else
volatile uint8_t* buffer = ptr;
volatile uint8_t *buffer = (volatile uint8_t*)ptr;
for (size_t i = 0U; i < length; ++i)
{
buffer[i] = 0U;