From 9b4415a7a0c38497f25d2791e5913a9b0dff14b3 Mon Sep 17 00:00:00 2001 From: jakcron Date: Fri, 8 Jan 2016 20:45:14 +0800 Subject: [PATCH] [ctrtool] Fix compile errors And comparisons which would have always returned false. --- ctrtool/Makefile | 21 ++++++++++++++++++--- ctrtool/stream.c | 2 +- ctrtool/utils.h | 6 ++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/ctrtool/Makefile b/ctrtool/Makefile index 73bd205..3842b54 100644 --- a/ctrtool/Makefile +++ b/ctrtool/Makefile @@ -3,12 +3,27 @@ SRC_DIR = . polarssl tinyxml OBJS = $(foreach dir,$(SRC_DIR),$(subst .c,.o,$(wildcard $(dir)/*.c))) $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) # Compiler Settings -LIBS = -static-libgcc -static-libstdc++ -CXXFLAGS = -I. -CFLAGS = -O2 -flto -Wall -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-result -I. OUTPUT = ctrtool +CXXFLAGS = -I. +CFLAGS = -O2 -flto -Wall -Wno-unused-variable -Wno-unused-result -I. CC = gcc CXX = g++ +ifeq ($(OS),Windows_NT) + #Windows Build CFG + CFLAGS += -Wno-unused-but-set-variable + LIBS += -static-libgcc -static-libstdc++ +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Darwin) + # OS X + CFLAGS += -Wno-unused-local-typedef + LIBS += -liconv + else + # Linux + CFLAGS += -Wno-unused-but-set-variable + LIBS += + endif +endif main: $(OBJS) $(CXX) -o $(OUTPUT) $(LIBS) $(OBJS) diff --git a/ctrtool/stream.c b/ctrtool/stream.c index e18dda3..dfb1ac6 100644 --- a/ctrtool/stream.c +++ b/ctrtool/stream.c @@ -119,7 +119,7 @@ int stream_out_flush(stream_out_context* ctx) if (ctx->outbufferpos > 0) { size_t writtenbytes = fwrite(ctx->outbuffer, 1, ctx->outbufferpos, ctx->outfile); - if (writtenbytes < 0) + if (writtenbytes == 0) // will be zero if nothing is written return 0; diff --git a/ctrtool/utils.h b/ctrtool/utils.h index 93bf219..990d900 100644 --- a/ctrtool/utils.h +++ b/ctrtool/utils.h @@ -46,8 +46,10 @@ inline int fseeko64(FILE *__stream, long long __off, int __whence) { return _fseeki64(__stream, __off, __whence); } -#else -extern int fseeko64 (FILE *__stream, off64_t __off, int __whence); +#elif __APPLE__ + #define fseeko64 fseek // OS X file I/O is 64bit +#elif __linux__ + extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence); #endif #ifdef __cplusplus