From bb94015a443a0aebaa93ee62f9f2738fa3a96784 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Wed, 27 Feb 2013 08:44:33 -0600 Subject: [PATCH] Fix for slow .incbin performance. --- direct.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/direct.c b/direct.c index 3471742..100db42 100644 --- a/direct.c +++ b/direct.c @@ -298,15 +298,15 @@ int d_noclear(void) // int d_incbin(void) { - int i, j; + int fd; int bytes = 0; - long pos, size; - char buf; + long pos, size, bytesRead; + char msg[256]; // Check to see if we're in BSS, and, if so, throw an error if (scattr & SBSS) { - errors("Cannot include binary file \"%s\" in BSS section", string[tok[1]]); + errors("cannot include binary file \"%s\" in BSS section", string[tok[1]]); return ERROR; } @@ -316,7 +316,7 @@ int d_incbin(void) return ERROR; } -// if ((j = open((char *)tok[1], _OPEN_INC)) >= 0) +#if 0 if ((j = open(string[tok[1]], _OPEN_INC)) >= 0) { size = lseek(j, 0L, SEEK_END); @@ -337,12 +337,57 @@ int d_incbin(void) } else { -// errors("cannot open include binary file (%s)", (char *)tok[1]); errors("cannot open include binary file (%s)", string[tok[1]]); return ERROR; } +#else + if ((fd = open(string[tok[1]], _OPEN_INC)) < 0) + { + errors("cannot open include binary file (%s)", string[tok[1]]); + return ERROR; + } + + size = lseek(fd, 0L, SEEK_END); + pos = lseek(fd, 0L, SEEK_SET); + chcheck(size); + + DEBUG + { + printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); + } + +#if 0 + for(i=0; i