+
+ mkbuffer (p);
+ }
+
+ return p;
+}
+
+
+WRAPPER2(int, setvbuf, FILE *stream, char *buf, int mode, size_t size)
+{
+ int rc = 0;
+ TRACE ("%s\n", __PRETTY_FUNCTION__);
+
+ MF_VALIDATE_EXTENT (stream, sizeof (*stream), __MF_CHECK_WRITE, "setvbuf stream");
+
+ unmkbuffer (stream);
+
+ if (buf != NULL)
+ MF_VALIDATE_EXTENT (buf, size, __MF_CHECK_WRITE, "setvbuf buffer");
+
+ /* Override the user only if it's an auto-allocated buffer request. Otherwise
+ assume that the supplied buffer is already known to libmudflap. */
+ if ((buf == NULL) && ((mode == _IOFBF) || (mode == _IOLBF)))
+ mkbuffer (stream);
+ else
+ rc = setvbuf (stream, buf, mode, size);
+
+ return rc;
+}
+
+
+#ifdef HAVE_SETBUF
+WRAPPER2(int, setbuf, FILE* stream, char *buf)
+{
+ return __mfwrap_setvbuf (stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
+}
+#endif
+
+#ifdef HAVE_SETBUFFER
+WRAPPER2(int, setbuffer, FILE* stream, char *buf, size_t sz)
+{
+ return __mfwrap_setvbuf (stream, buf, buf ? _IOFBF : _IONBF, sz);
+}
+#endif
+
+#ifdef HAVE_SETLINEBUF
+WRAPPER2(int, setlinebuf, FILE* stream)
+{
+ return __mfwrap_setvbuf(stream, NULL, _IOLBF, 0);
+}
+#endif
+
+
+
+WRAPPER2(FILE *, fdopen, int fd, const char *mode)
+{
+ size_t n;
+ FILE *p;
+ TRACE ("%s\n", __PRETTY_FUNCTION__);
+
+ n = strlen (mode);
+ MF_VALIDATE_EXTENT (mode, CLAMPADD(n, 1), __MF_CHECK_READ, "fdopen mode");
+
+ p = fdopen (fd, mode);
+ if (NULL != p) {
+#ifdef MF_REGISTER_fopen
+ __mf_register (p, sizeof (*p), MF_REGISTER_fopen, "fdopen result");
+#endif
+ MF_VALIDATE_EXTENT (p, sizeof (*p), __MF_CHECK_WRITE, "fdopen result");
+
+ mkbuffer (p);
+ }
+
+ return p;
+}
+
+
+WRAPPER2(FILE *, freopen, const char *path, const char *mode, FILE *s)
+{
+ size_t n;
+ FILE *p;
+ TRACE ("%s\n", __PRETTY_FUNCTION__);
+
+ n = strlen (path);
+ MF_VALIDATE_EXTENT (path, CLAMPADD(n, 1), __MF_CHECK_READ, "freopen path");
+
+ MF_VALIDATE_EXTENT (s, (sizeof (*s)), __MF_CHECK_WRITE, "freopen stream");
+ unmkbuffer (s);
+
+ n = strlen (mode);
+ MF_VALIDATE_EXTENT (mode, CLAMPADD(n, 1), __MF_CHECK_READ, "freopen mode");
+
+ p = freopen (path, mode, s);
+ if (NULL != p) {
+#ifdef MF_REGISTER_fopen
+ __mf_register (p, sizeof (*p), MF_REGISTER_fopen, "freopen result");
+#endif
+ MF_VALIDATE_EXTENT (p, sizeof (*p), __MF_CHECK_WRITE, "freopen result");
+
+ mkbuffer (p);