Main Menu

Forums Forth Programming Calling CLOSE-FILE twice

This topic contains 2 replies, has 3 voices, and was last updated by  Leon Wagner 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4381

    Rene Hartmann
    Participant

    I wonder if it is safe to call CLOSE-FILE on a file id that has been closed before.

    SwiftForth returns -197 if CLOSE-FILE is called twice. Can one rely on this behaviour?

    I checked with GForth, and it crashes when CLOSE-FILE is called twice. I guess there a fileid is a pointer to a block of memory that is freed when CLOSE-FILE is called.


    René

    #4415

    allen@a2d2.com
    Participant

    My original program:

    : FILE-CLOSE \ ( — )
    fileid @ CLOSE-FILE diskfault ! ;

    My trial programs:

    : FILE-CLOSE \ ( — )
    fileid @ CLOSE-FILE diskfault ! fileid @ CLOSE-FILE DROP ;

    : FILE-CLOSE \ ( — )
    fileid @ CLOSE-FILE diskfault ! 0 CLOSE-FILE DROP ;

    Both trial programs worked properly without crashing the computer. My program that calls this opens and closes hundreds of files in a fraction of a second, not just one file, so I feel my test is pretty good.

    Best wishes — Allen Anway

    #4995

    Leon Wagner
    Keymaster

    The Forth Standard definition of CLOSE-FILE says this:

    CLOSE-FILE
    ( fileid — ior )
    Close the file identified by fileid. ior is the implementation-defined I/O result code.

    The list of standard ior and throw code values are defined in the Forth-2012 standard here. It specifies -62 as the ior for a fail in CLOSE-FILE. We’ll be updating our throw codes to match the new standard in an upcoming release. I would not expect CLOSE-FILE to crash or do anything other than return an error ior if the fileid can’t be closed (for whatever reason).

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.