+// Check the return code from a fopen-style function (returns a non-nullptr
+// FILE* on success, nullptr on error, sets errno). Works with fopen, fdopen,
+// freopen, tmpfile, etc.
+template <class... Args>
+void checkFopenError(FILE* fp, Args&&... args) {
+ if (UNLIKELY(!fp)) {
+ throwSystemError(std::forward<Args>(args)...);
+ }
+}
+
+template <class... Args>
+void checkFopenErrorExplicit(FILE* fp, int savedErrno, Args&&... args) {
+ if (UNLIKELY(!fp)) {
+ throwSystemErrorExplicit(savedErrno, std::forward<Args>(args)...);
+ }
+}