mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Set binary mode and unset safe dll search
This commit is contained in:
parent
770c076500
commit
0a0a760290
@ -9,6 +9,8 @@
|
|||||||
#include <Shobjidl.h>
|
#include <Shobjidl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <io.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#define PRINTERR(x) fprintf(stderr, x); fflush(stderr);
|
#define PRINTERR(x) fprintf(stderr, x); fflush(stderr);
|
||||||
#define REPORTERR(x) { PRINTERR(x); ret = 1; goto error; }
|
#define REPORTERR(x) { PRINTERR(x); ret = 1; goto error; }
|
||||||
@ -76,6 +78,7 @@ bool read_string(unsigned short sz, LPWSTR* ans) {
|
|||||||
#define READ(x, y) if (!read_bytes((x), (y))) return 1;
|
#define READ(x, y) if (!read_bytes((x), (y))) return 1;
|
||||||
#define CHECK_KEY(x) (key_size == sizeof(x) - 1 && memcmp(buf, x, sizeof(x) - 1) == 0)
|
#define CHECK_KEY(x) (key_size == sizeof(x) - 1 && memcmp(buf, x, sizeof(x) - 1) == 0)
|
||||||
#define READSTR(x) READ(sizeof(unsigned short), buf); if(!read_string(*((unsigned short*)buf), &x)) return 1;
|
#define READSTR(x) READ(sizeof(unsigned short), buf); if(!read_string(*((unsigned short*)buf), &x)) return 1;
|
||||||
|
#define SETBINARY(x) if(_setmode(_fileno(x), _O_BINARY) == -1) { PRINTERR("Failed to set binary mode"); return 1; }
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
|
||||||
char buf[257];
|
char buf[257];
|
||||||
@ -85,6 +88,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
|
|||||||
unsigned short len = 0;
|
unsigned short len = 0;
|
||||||
LPWSTR title = NULL;
|
LPWSTR title = NULL;
|
||||||
|
|
||||||
|
SETBINARY(stdout); SETBINARY(stdin); SETBINARY(stderr);
|
||||||
|
// The calibre executables call SetDllDirectory, we unset it here just in
|
||||||
|
// case it interferes with some idiotic shell extension or the other
|
||||||
|
SetDllDirectory(NULL);
|
||||||
|
|
||||||
while(!feof(stdin)) {
|
while(!feof(stdin)) {
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
if(!read_bytes(1, buf, true)) { if (feof(stdin)) break; return 1;}
|
if(!read_bytes(1, buf, true)) { if (feof(stdin)) break; return 1;}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user