From bb12fbca378484d0098f9752d112c87a4338676b Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 16 Jan 2006 23:42:17 +0100 Subject: [PATCH] Add protocol/common files ;) --- src/protocol/common.c | 37 +++++++++++++++++++++++++++++++++++++ src/protocol/common.h | 7 +++++++ 2 files changed, 44 insertions(+) create mode 100644 src/protocol/common.c create mode 100644 src/protocol/common.h diff --git a/src/protocol/common.c b/src/protocol/common.c new file mode 100644 index 000000000..2195a9d17 --- /dev/null +++ b/src/protocol/common.c @@ -0,0 +1,37 @@ +/* Shared protocol functions */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_SYS_TIME_H +#include /* FreeBSD needs this before resource.h */ +#endif +#include /* FreeBSD needs this before resource.h */ +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "elinks.h" + +#include "protocol/common.h" + + +/* Close all non-terminal file descriptors. */ +void +close_all_non_term_fd(void) +{ + int n; + int max = 1024; +#ifdef RLIMIT_NOFILE + struct rlimit lim; + + if (!getrlimit(RLIMIT_NOFILE, &lim)) + max = lim.rlim_max; +#endif + for (n = 3; n < max; n++) + close(n); +} diff --git a/src/protocol/common.h b/src/protocol/common.h new file mode 100644 index 000000000..1f43b7900 --- /dev/null +++ b/src/protocol/common.h @@ -0,0 +1,7 @@ +#ifndef EL__PROTOCOL_COMMON_H +#define EL__PROTOCOL_COMMON_H + +/* Close all non-terminal file descriptors. */ +void close_all_non_term_fd(void); + +#endif