SCCS-vsn: usr.bin/mail/popen.c 5.18
-static char sccsid[] = "@(#)popen.c 5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)popen.c 5.18 (Berkeley) %G%";
#endif /* not lint */
#include "rcv.h"
#endif /* not lint */
#include "rcv.h"
+/*
+ * XXX
+ * The old mail code used getdtablesize() to return the max number of
+ * file descriptors. That's a *real* big number now. Fake it.
+ */
+#define MAX_FILE_DESCRIPTORS 64
+#define MAX_FILE_DESCRIPTORS_TO_CLOSE 20
FILE *
Popen(cmd, mode)
char *cmd;
FILE *
Popen(cmd, mode)
char *cmd;
- pid = (int *) malloc((unsigned) sizeof (int) * getdtablesize());
+ pid = malloc((u_int)sizeof (int) * MAX_FILE_DESCRIPTORS);
if (pipe(p) < 0)
return NULL;
if (*mode == 'r') {
if (pipe(p) < 0)
return NULL;
if (*mode == 'r') {
dup2(infd, 0);
if (outfd >= 0)
dup2(outfd, 1);
dup2(infd, 0);
if (outfd >= 0)
dup2(outfd, 1);
- for (i = getdtablesize(); --i > 2;)
+ for (i = MAX_FILE_DESCRIPTORS_TO_CLOSE; --i > 2;)
close(i);
for (i = 1; i <= NSIG; i++)
if (mask & sigmask(i))
close(i);
for (i = 1; i <= NSIG; i++)
if (mask & sigmask(i))