rpm-build/lib/closeall.c

34 lines
503 B
C
Raw Normal View History

2003-11-24 22:20:13 +03:00
#include <unistd.h>
#include <errno.h>
2002-03-25 23:37:46 +03:00
2003-11-24 22:20:13 +03:00
#ifdef __linux__
2002-03-25 23:37:46 +03:00
#include <linux/limits.h>
#endif
2003-11-24 21:59:03 +03:00
int rpm_close_all (void)
2002-03-25 23:37:46 +03:00
{
int fd, max;
2003-11-24 21:59:03 +03:00
max = sysconf (_SC_OPEN_MAX);
if (max <= 0)
2002-03-25 23:37:46 +03:00
return -1;
2003-11-24 22:20:13 +03:00
#ifdef __linux__
2003-11-24 21:59:03 +03:00
if (max < NR_OPEN)
2002-03-25 23:37:46 +03:00
max = NR_OPEN;
#endif
2003-11-24 21:59:03 +03:00
for (fd = STDERR_FILENO + 1; fd < max; ++fd)
2002-03-25 23:37:46 +03:00
{
2003-11-24 21:59:03 +03:00
if (close (fd) && errno != EBADF)
2002-03-25 23:37:46 +03:00
/*
* Possible errors are:
* EINTR: the close() call was interrupted by a signal;
* EIO: an I/O error occurred.
*/
return -1;
}
return 0;
}