/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
- * $Id: getBufferMode.c,v 1.1 1998/04/10 10:54:33 simonm Exp $
+ * $Id: getBufferMode.c,v 1.3 1998/12/02 13:27:35 simonm Exp $
*
* hIs...Buffered Runtime Support
*/
#define GBM_ERR (-3)
StgInt
-getBufferMode(StgAddr fp)
+getBufferMode(ptr)
+StgForeignPtr ptr;
{
+ IOFileObject* fo = (IOFileObject*)ptr;
struct stat sb;
+ int fd = fo->fd;
/* Try to find out the file type */
- while (fstat(fileno((FILE *) fp), &sb) < 0) {
+ while (fstat(fd, &sb) < 0) {
/* highly unlikely */
if (errno != EINTR) {
cvtErrno();
}
}
/* Terminals are line-buffered by default */
- if (S_ISCHR(sb.st_mode) && isatty(fileno((FILE *) fp)) == 1)
+ if (S_ISCHR(sb.st_mode) && isatty(fd) == 1) {
+ fo ->flags |= FILEOBJ_LB;
return GBM_LB;
/* Default size block buffering for the others */
- else
+ } else {
+ fo ->flags |= FILEOBJ_BB;
return GBM_BB;
+ }
}