+int
+djgpp_fflush (FILE *fp)
+{
+ int res;
+
+ if ((res = fflush(fp)) == 0 && fp) {
+ Stat_t s;
+ if (Fstat(fileno(fp), &s) == 0 && !S_ISSOCK(s.st_mode))
+ res = fsync(fileno(fp));
+ }
+/*
+ * If the flush succeeded but set end-of-file, we need to clear
+ * the error because our caller may check ferror(). BTW, this
+ * probably means we just flushed an empty file.
+ */
+ if (res == 0 && fp && ferror(fp) == EOF) clearerr(fp);
+
+ return res;
+}
+
+int djgpp_get_stream_mode(FILE *f)
+{
+ extern char *__file_handle_modes;
+
+ int mode = __file_handle_modes[fileno(f)];
+ if (f->_flag & _IORW)
+ return mode | O_RDWR;
+ if (f->_flag & _IOWRT)
+ return mode | O_WRONLY;
+ return mode | O_RDONLY;
+}
+