home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff319.lzh
/
CNewsSrc
/
cnews.orig.lzh
/
libc
/
stdfdopen.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-27
|
539b
|
28 lines
/*
* stdfdopen - ensure that the standard i/o descriptors are open,
* to avoid mayhem.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef NSYSFILE
#define NSYSFILE 3 /* hmm, not on V8 */
#endif
extern int errno;
void
stdfdopen() /* ensure standard descriptors are open */
{
register int fd;
struct stat stbuf;
for (fd = 0; fd < NSYSFILE; fd++)
if (fstat(fd, &stbuf) < 0 && errno == EBADF)
if (open("/dev/null", 2) != fd) /* open read/write */
exit(1); /* bad news */
}