Our replies to Sjoerd crossed each other. I hope mine explained the
situation sufficiently (no, there is no way to tell whether there is
buffered data -- you have to make the file unbuffered).
Here's a patch to posixmodule.c that adds a third 'bufsize' parameter
to fdopen() and popen().
===================================================================
RCS file: /ufs/guido/CVSROOT/python/Modules/posixmodule.c,v
retrieving revision 2.44
diff -c -r2.44 posixmodule.c
*** 2.44 1995/01/04 19:10:15
--- posixmodule.c 1995/01/10 15:30:28
***************
*** 868,876 ****
object *self;
object *args;
{
! char *name, *mode;
FILE *fp;
! if (!getargs(args, "(ss)", &name, &mode))
return NULL;
BGN_SAVE
fp = popen(name, mode);
--- 868,879 ----
object *self;
object *args;
{
! char *name;
! char *mode = "r";
! int bufsize = -1;
FILE *fp;
! object *f;
! if (!newgetargs(args, "s|si", &name, &mode, &bufsize))
return NULL;
BGN_SAVE
fp = popen(name, mode);
***************
*** 877,883 ****
END_SAVE
if (fp == NULL)
return posix_error();
! return newopenfileobject(fp, name, mode, pclose);
}
#ifdef HAVE_SETUID
--- 880,889 ----
END_SAVE
if (fp == NULL)
return posix_error();
! f = newopenfileobject(fp, name, mode, pclose);
! if (f != NULL)
! setfilebufsize(f, bufsize);
! return f;
}
#ifdef HAVE_SETUID
***************
*** 1272,1280 ****
{
extern int fclose PROTO((FILE *));
int fd;
! char *mode;
FILE *fp;
! if (!getargs(args, "(is)", &fd, &mode))
return NULL;
BGN_SAVE
fp = fdopen(fd, mode);
--- 1278,1288 ----
{
extern int fclose PROTO((FILE *));
int fd;
! char *mode = "r";
! int bufsize = -1;
FILE *fp;
! object *f;
! if (!newgetargs(args, "i|si", &fd, &mode, &bufsize))
return NULL;
BGN_SAVE
fp = fdopen(fd, mode);
***************
*** 1281,1289 ****
END_SAVE
if (fp == NULL)
return posix_error();
! /* From now on, ignore SIGPIPE and let the error checking
! do the work. */
! return newopenfileobject(fp, "(fdopen)", mode, fclose);
}
static object *
--- 1289,1298 ----
END_SAVE
if (fp == NULL)
return posix_error();
! f = newopenfileobject(fp, "(fdopen)", mode, fclose);
! if (f != NULL)
! setfilebufsize(f, bufsize);
! return f;
}
static object *
***************
*** 1369,1375 ****
{"getuid", posix_getuid},
{"kill", posix_kill},
#endif /* !NT */
! {"popen", posix_popen},
#ifdef HAVE_SETUID
{"setuid", posix_setuid},
#endif /* HAVE_SETUID */
--- 1378,1384 ----
{"getuid", posix_getuid},
{"kill", posix_kill},
#endif /* !NT */
! {"popen", posix_popen, 1},
#ifdef HAVE_SETUID
{"setuid", posix_setuid},
#endif /* HAVE_SETUID */
***************
*** 1405,1411 ****
{"read", posix_read},
{"write", posix_write},
{"fstat", posix_fstat},
! {"fdopen", posix_fdopen},
{"pipe", posix_pipe},
{NULL, NULL} /* Sentinel */
};
--- 1414,1420 ----
{"read", posix_read},
{"write", posix_write},
{"fstat", posix_fstat},
! {"fdopen", posix_fdopen, 1},
{"pipe", posix_pipe},
{NULL, NULL} /* Sentinel */
};
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>