[Issue 1583] New: std.cstream.CFile cannot be detached from FILE*

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 15 00:04:35 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1583

           Summary: std.cstream.CFile cannot be detached from FILE*
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: wbaxter at gmail.com


The CFile class provides a nice wrapper around a C FILE*, but it provides NO
way of disconnecting itself from the file, and ultimately will try to close
whatever file you pass to it.

In particular I think the behavior of the file(FILE*) setter and the
constructor should be considered buggy.  They pretend the FILE is open even if
it is NULL.

If those methods actually checked for null, and didn't set the isopen flag in
those cases, then setting to null could be used as a way to detach the FILE.

As is, if you set the FILE* to null, there's no crash, but the CFile will
inevitably try to call fclose() on that null handle, which it should not, since
that will cause errno to get set.

Anyway, there should be a way to detach the file from the CFile.  I suggest
just using "set to null" to signal that, but I'd be happy with anything.


-- 



More information about the Digitalmars-d-bugs mailing list