Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESIZE-FILE test fails on MSYS2/Cygwin #189

Closed
guberathome opened this issue Jan 2, 2025 · 2 comments · Fixed by #198
Closed

RESIZE-FILE test fails on MSYS2/Cygwin #189

guberathome opened this issue Jan 2, 2025 · 2 comments · Fixed by #198

Comments

@guberathome
Copy link
Contributor

guberathome commented Jan 2, 2025

RESIZE-FILE tests in t_file.fth fail with these messages:

cd ../../fth && ../platforms/unix/pforth_standalone -q t_file.fth
Include t_tools.fth
    include added 1712 bytes,38292 left.
(got=87, expected=37) INCORRECT RESULT: T{ FID2 @ FILE-SIZE -> 37. 0 }T
(got=87, expected=37) INCORRECT RESULT: T{ CBUF BUF 100 FID2 @ READ-FILE -> 37 0 }T
(got=-1, expected=0) INCORRECT RESULT: T{ PAD 38 BUF 38 S= -> FALSE }T
...
  91 passed,    3 failed.
make: *** [Makefile:172: test] Error 40

Tested on Cygwin (x86_64) and MSYS2 (Cygwin based)

@guberathome
Copy link
Contributor Author

Analysis:

Augmenting the sources...

static bool_t TruncateFile( FileStream *File, long Newsize )
{
    bool_t Error = TRUE;
    if( fseek( File, 0, SEEK_SET ) == 0)
    {
        FileStream *TmpFile = tmpfile();
        if( TmpFile != NULL )
        {
			int debugging = 1;
if(debugging) printf( "--- debug-00\n" );
            if( CopyFile( File, TmpFile, Newsize )) goto cleanup;
if(debugging) printf( "--- debug-01\n" );
            if( fseek( TmpFile, 0, SEEK_SET ) != 0 ) goto cleanup;
if(debugging) printf( "--- debug-02\n" );
            if( freopen( getFilePathFromStream(File), "w+b", File ) == NULL ) goto cleanup;
if(debugging) printf( "--- debug-03 ftell=%li\n", ftell(File) );
            if( ftell(File)!=0 ) goto cleanup;  /* Cygwin reopens File BEHIND the content */
if(debugging) printf( "--- debug-04\n" );
            if( CopyFile( TmpFile, File, Newsize )) goto cleanup;
if(debugging) printf( "--- debug-05 => did it :-) \n" );
            Error = FALSE;

cleanup:
            fclose( TmpFile );
        }
    }
    return Error;
}

... shows on {Linux, FreeBSD, NetBSD}:

cd ../../fth && ../platforms/unix/pforth_standalone -q t_file.fth
Include t_tools.fth
    include added 1592 bytes,38412 left.
--- debug-00
--- debug-01
--- debug-02
--- debug-03 ftell=0
--- debug-04
--- debug-05 => did it :-) 
...
  94 passed,    0 failed.
PForth Tests PASSED

... but on Cygwin / MSYS2:

cd ../../fth && ../platforms/unix/pforth_standalone -q t_file.fth
Include t_tools.fth
    include added 1712 bytes,38292 left.
--- debug-00
--- debug-01
--- debug-02
--- debug-03 ftell=50
(got=-74, expected=0) INCORRECT RESULT: T{ 37. FID2 @ RESIZE-FILE -> 0 }T
(got=50, expected=37) INCORRECT RESULT: T{ FID2 @ FILE-SIZE -> 37. 0 }T
(got=50, expected=37) INCORRECT RESULT: T{ CBUF BUF 100 FID2 @ READ-FILE -> 37 0 }T
(got=-1, expected=0) INCORRECT RESULT: T{ PAD 38 BUF 38 S= -> FALSE }T
...
  90 passed,    4 failed.
make: *** [Makefile:165: test] Error 40

Again the problem is with the freopen() bit in TruncateFile().

@philburk philburk changed the title test suite fails on MSYS2/Cygwin RESIZE-FILE test fails on MSYS2/Cygwin Jan 5, 2025
@philburk
Copy link
Owner

This passes on MacOS

../platforms/unix/pforth_standalone -q t_file.fth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants