Hacker News new | ask | show | jobs
by cjensen 335 days ago
FreeBSD's implementation of FILE is a nice object-oriented structure which anyone could derive from. Super-easy to make FILE point to a memory buffer or some other user code. I used that a bunch a long time ago.

Obviously making FILE opaque completely breaks every program that used this feature, so no surprise it was reverted.

2 comments

In the FreeBSD case, far from breaking "every program" it breaks very little at all. In fact it broke 1 thing at the time. Unfortunately, that 1 thing happened to be sysinstall(8).

stdin, stdout, and stderr were already pointers rather than array element addresses, and the external symbol references to __stdinp, __stdoutp, and __stderrp did not change; compiled code using the old macros continued to work as the actual structure layout was not changed; compiled code using FILE* would have continued to work as the pointer implementation didn't change; compiled C++ code with C++ function parameter overloading would have continued to link as the underlying struct type did not change; source code using the ferror_unlocked() and suchlike function-like macros would have not needed changing as there were already ferror_unlocked() and suchlike functions and those remained.

Looking at things like https://reviews.freebsd.org/D4488 from 2015 there was definitely stuff in the ports tree that would have broken back in 2008. But that won't break now should this change be made again, and that's not base.

What actually broke was libftpio, a library that was in base up until 2011, and definitely won't break now, nearly 14 years after being removed for being orphaned after sysinstall(8) itself has gone away.

* https://cgit.freebsd.org/src/commit/lib/libftpio?id=430f2c87...

fopencookie, fmemopen, you don't need transparency.
fopencookie seems glibc-specific, so unavailable on BSD.
BSD has had funopen(3) since 4.4, so it has an alternative. FreeBSD has implemented fopencookie(3) since v11, but FreeBSD is the BSD most willing to implement Linux interfaces for various reasons.