Linux compile fixes.

This commit is contained in:
LoRd_MuldeR 2020-10-13 15:37:40 +02:00
parent 865702f879
commit 75f929e4e5
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
4 changed files with 30 additions and 16 deletions

View File

@ -10,6 +10,7 @@
#include "crc.h"
#include <string.h>
#include <time.h>
#include <inttypes.h>
static void print_string(const char *const text, const size_t length)
{
@ -290,13 +291,14 @@ static int decrypt(const CHR* const passphrase, const CHR* const input, const CH
if (crc_actual != crc_expected)
{
FPRINTF(stderr, T("CRC error: Checksum mismatch detected! [0x%016") FMT_I64X T(" vs. 0x%016") FMT_I64X T("\n\nWrong passphrase?\n\n"), crc_actual, crc_expected);
FPRINTF(stderr, T("CRC error: Checksum mismatch detected! [expected: 0x%016") T(PRIX64) T(", actual: 0x%016") T(PRIX64) T("]\n\n"), crc_actual, crc_expected);
FPUTS(T("Wrong passphrase or corrupted file?\n\n"), stderr);
goto clean_up;
}
result = 0;
FPUTS(T("CRC checksum is correct :-)\n\n"), stderr);
FPUTS(T("CRC checksum is correct.\n\n"), stderr);
fflush(stderr);
clean_up:
@ -327,8 +329,8 @@ clean_up:
int MAIN(int argc, CHR* argv[])
{
FPRINTF(stderr, T("MCrypt Utility [%") FMT_char T("]\n"), __DATE__" "__TIME__);
FPRINTF(stderr, T("Powered by libMCrypt v%") FMT_char T(" [%") FMT_char T("]\n\n"), LIBMCRYPT_VERSION, LIBMCRYPT_BUILDNO);
FPRINTF(stderr, T("MCrypt Utility [%") T(PRIstr) T("]\n"), __DATE__" "__TIME__);
FPRINTF(stderr, T("Powered by libMCrypt v%") T(PRIstr) T(" [%") T(PRIstr) T("]\n\n"), LIBMCRYPT_VERSION, LIBMCRYPT_BUILDNO);
if (argc < 4)
{

View File

@ -10,7 +10,6 @@
#define MAIN wmain
#define CHR wchar_t
#define _T(X) L##X
#define T(X) _T(X)
#define STRLEN(X) wcslen((X))
#define STRICMP(X,Y) _wcsicmp((X),(Y))
#define FPUTS(X,Y) fputws((X),(Y))
@ -20,25 +19,25 @@
#define FSTAT64(X,Y) _fstati64((X),(Y))
#define STAT64_T struct _stati64
#ifdef __MINGW32__
#define FMT_char L"hs"
#define FMT_I64X L"llX"
#define PRIstr "hs"
#else
#define FMT_char L"S"
#define FMT_I64X L"I64X"
#define PRIstr "S"
#endif
#else
#define MAIN main
#define CHR char
#define _T(X) X
#define STRLEN(X) strlen((X))
#define STRICMP(X,Y) stricmp((X),(Y))
#define STRICMP(X,Y) strcasecmp((X),(Y))
#define FPUTS(X,Y) fputs((X),(Y))
#define FPRINTF(X,Y,...) fprintf((X),(Y),__VA_ARGS__)
#define FOPEN(X,Y) fopen((X),(Y))
#define FILENO(X) fileno((X))
#define FSTAT64(X,Y) fstat64((X),(Y))
#define STAT64_T struct stat64
#define FMT_char "s"
#define FMT_I64X L"llX"
#define PRIstr "s"
#endif
#define T(X) _T(X)
#endif

View File

@ -6,13 +6,21 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#define _CRT_SECURE_NO_WARNINGS 1
#else
#define _LARGEFILE64_SOURCE 1
#endif
#include "utils.h"
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef _WIN32
#include <Windows.h>
#include <fcntl.h>
#define S_IFMT _S_IFMT
#define S_IFDIR _S_IFDIR
#define S_IFIFO _S_IFIFO
#endif
void erase(void *const ptr, const size_t length)
@ -62,8 +70,8 @@ uint64_t get_file_size(FILE *const file)
{
return UINT64_MAX;
}
uint16_t file_type = stat.st_mode & _S_IFMT;
if ((file_type != _S_IFDIR) && (file_type != _S_IFIFO))
uint16_t file_type = stat.st_mode & S_IFMT;
if ((file_type != S_IFDIR) && (file_type != S_IFIFO))
{
return (stat.st_size >= 0LL) ? ((uint64_t)stat.st_size) : 0U;
}

View File

@ -9,6 +9,11 @@
#include "utils.h"
#ifdef __unix__
#include <unistd.h>
#include <fcntl.h>
#endif
int mcrypt_random_bytes(uint8_t* const buffer, const size_t length)
{
#ifdef _WIN32
@ -38,7 +43,7 @@ int mcrypt_random_bytes(uint8_t* const buffer, const size_t length)
const int fd = open(PATH[i], O_RDONLY);
if (fd >= 0)
{
if (read(fd, buffer, length) < length)
if (read(fd, buffer, length) >= length)
{
result = 0;
}