X-Git-Url: http://git.subgeniuskitty.com/pforth/.git/blobdiff_plain/e0d21c12cf924ad826eb0e73a10c5167f0195f65..4d9c915d183f67c0c066996816524e863343c1d6:/csrc/pf_inner.c diff --git a/csrc/pf_inner.c b/csrc/pf_inner.c index f673075..e435d49 100644 --- a/csrc/pf_inner.c +++ b/csrc/pf_inner.c @@ -26,12 +26,6 @@ ** ***************************************************************/ -#ifndef AMIGA -#include -#else -typedef long off_t; -#endif - #include "pf_all.h" #if defined(WIN32) && !defined(__MINGW32__) @@ -199,6 +193,24 @@ static void TraceNames( ExecToken Token, cell_t Level ) /* Use local copy of CODE_BASE for speed. */ #define LOCAL_CODEREL_TO_ABS( a ) ((cell_t *) (((cell_t) a) + CodeBase)) +/* Truncate the unsigned double cell integer LO/HI to an uint64_t. */ +static uint64_t UdToUint64( ucell_t Lo, ucell_t Hi ) +{ + return (( 2 * sizeof(ucell_t) == sizeof(uint64_t) ) + ? (((uint64_t)Lo) | (((uint64_t)Hi) >> (sizeof(ucell_t) * 8))) + : Lo ); +} + +/* Return TRUE if the unsigned double cell integer LO/HI is not greater + * then the greatest uint64_t. + */ +static int UdIsUint64( ucell_t Lo, ucell_t Hi ) +{ + return (( 2 * sizeof(ucell_t) == sizeof(uint64_t) ) + ? TRUE + : Hi == 0 ); +} + static const char *pfSelectFileModeCreate( int fam ); static const char *pfSelectFileModeOpen( int fam ); @@ -1025,13 +1037,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); /* Determine file size by seeking to end and returning position. */ FileID = (FileStream *) TOS; { - off_t endposition, offsetHi; - off_t original = sdTellFile( FileID ); + file_offset_t endposition, offsetHi; + file_offset_t original = sdTellFile( FileID ); sdSeekFile( FileID, 0, PF_SEEK_END ); endposition = sdTellFile( FileID ); M_PUSH(endposition); /* Just use a 0 if they are the same size. */ - offsetHi = (sizeof(off_t) > sizeof(cell_t)) ? (endposition >> (8*sizeof(cell_t))) : 0 ; + offsetHi = (sizeof(file_offset_t) > sizeof(cell_t)) + ? (endposition >> (8*sizeof(cell_t))) : 0 ; M_PUSH(offsetHi); sdSeekFile( FileID, original, PF_SEEK_SET ); TOS = (original < 0) ? -4 : 0 ; /* !!! err num */ @@ -1048,11 +1061,12 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_FILE_REPOSITION: /* ( ud fid -- ior ) */ { - off_t offset; + file_offset_t offset; FileID = (FileStream *) TOS; offset = M_POP; /* Avoid compiler warnings on Mac. */ - offset = (sizeof(off_t) > sizeof(cell_t)) ? (offset << 8*sizeof(cell_t)) : 0 ; + offset = (sizeof(file_offset_t) > sizeof(cell_t)) + ? (offset << 8*sizeof(cell_t)) : 0 ; offset += M_POP; TOS = sdSeekFile( FileID, offset, PF_SEEK_SET ); } @@ -1060,13 +1074,14 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); case ID_FILE_POSITION: /* ( fid -- ud ior ) */ { - off_t position; - off_t offsetHi; + file_offset_t position; + file_offset_t offsetHi; FileID = (FileStream *) TOS; position = sdTellFile( FileID ); M_PUSH(position); /* Just use a 0 if they are the same size. */ - offsetHi = (sizeof(off_t) > sizeof(cell_t)) ? (position >> (8*sizeof(cell_t))) : 0 ; + offsetHi = (sizeof(file_offset_t) > sizeof(cell_t)) + ? (position >> (8*sizeof(cell_t))) : 0 ; M_PUSH(offsetHi); TOS = (position < 0) ? -4 : 0 ; /* !!! err num */ } @@ -1111,7 +1126,9 @@ DBUG(("XX ah,m,l = 0x%8x,%8x,%8x - qh,l = 0x%8x,%8x\n", ah,am,al, qh,ql )); FileStream *File = (FileStream *) TOS; ucell_t SizeHi = (ucell_t) M_POP; ucell_t SizeLo = (ucell_t) M_POP; - TOS = sdResizeFile( File, SizeLo, SizeHi ); + TOS = ( UdIsUint64( SizeLo, SizeHi ) + ? sdResizeFile( File, UdToUint64( SizeLo, SizeHi )) + : THROW_RESIZE_FILE ); } endcase;