From e6b181bea747628232b9b3c1fc83791e728a91c5 Mon Sep 17 00:00:00 2001 From: Vladislav Valtchev Date: Tue, 19 Nov 2019 13:49:35 +0200 Subject: [PATCH 1/2] Call read() in a loop in W_StdC_Read() The read() syscall does *not* guaratee that the whole buffer will be filled before returning. Partial reads must be expected. --- fbdoom/w_file_stdc_unbuffered.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fbdoom/w_file_stdc_unbuffered.c b/fbdoom/w_file_stdc_unbuffered.c index e59e63b..b271e39 100644 --- a/fbdoom/w_file_stdc_unbuffered.c +++ b/fbdoom/w_file_stdc_unbuffered.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -92,7 +93,8 @@ size_t W_StdC_Read(wad_file_t *wad, unsigned int offset, void *buffer, size_t buffer_len) { stdc_wad_file_t *stdc_wad; - size_t result; + size_t result = 0; + int rc; stdc_wad = (stdc_wad_file_t *) wad; @@ -102,7 +104,21 @@ size_t W_StdC_Read(wad_file_t *wad, unsigned int offset, // Read into the buffer. - result = read(stdc_wad->fd, buffer, buffer_len); + do { + + rc = read(stdc_wad->fd, (char *)buffer + result, buffer_len - result); + + if (rc <= 0) { + + if (rc < 0 && errno == EINTR) + continue; + + break; + } + + result += rc; + + } while (result < buffer_len); return result; } From f5725ff6f23aa2ac77c11db9e414329da5ba56bf Mon Sep 17 00:00:00 2001 From: Vladislav Valtchev Date: Tue, 19 Nov 2019 14:13:56 +0200 Subject: [PATCH 2/2] Introduce the NOSDL option in the Makefile For many reasons, the SDL library might not be available on some systems. Therefore, it's useful to offer a way to build without it. With this patch, it's possible to build fbDoom without SDL in the following way: make NOSDL=1 --- fbdoom/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fbdoom/Makefile b/fbdoom/Makefile index cb88745..fb32c7b 100644 --- a/fbdoom/Makefile +++ b/fbdoom/Makefile @@ -23,7 +23,11 @@ CC=$(CROSS_COMPILE)gcc # gcc or g++ CFLAGS+=-ggdb3 -Os LDFLAGS+=-Wl,--gc-sections CFLAGS+=-ggdb3 -Wall -DNORMALUNIX -DLINUX -DSNDSERV # -DUSEASM -LIBS+=-lm -lc -lSDL +LIBS+=-lm -lc + +ifneq ($(NOSDL),1) + LIBS+= -lSDL +endif # subdirectory for objects OBJDIR=build