diff options
Diffstat (limited to 'src/microhttpd/mhd_sockets.c')
-rw-r--r-- | src/microhttpd/mhd_sockets.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_sockets.c b/src/microhttpd/mhd_sockets.c index 21e265f6..3fda6138 100644 --- a/src/microhttpd/mhd_sockets.c +++ b/src/microhttpd/mhd_sockets.c | |||
@@ -297,3 +297,31 @@ MHD_socket_nonblocking_ (MHD_socket sock) | |||
297 | #endif /* MHD_WINSOCK_SOCKETS */ | 297 | #endif /* MHD_WINSOCK_SOCKETS */ |
298 | return !0; | 298 | return !0; |
299 | } | 299 | } |
300 | |||
301 | |||
302 | /** | ||
303 | * Change socket options to be non-inheritable. | ||
304 | * | ||
305 | * @param sock socket to manipulate | ||
306 | * @return non-zero if succeeded, zero otherwise | ||
307 | * @warning Does not set socket error on W32. | ||
308 | */ | ||
309 | int | ||
310 | MHD_socket_noninheritable_ (MHD_socket sock) | ||
311 | { | ||
312 | #if defined(MHD_POSIX_SOCKETS) | ||
313 | int flags; | ||
314 | |||
315 | flags = fcntl (sock, F_GETFD); | ||
316 | if (-1 == flags) | ||
317 | return 0; | ||
318 | |||
319 | if ( ((flags | FD_CLOEXEC) != flags) && | ||
320 | (0 != fcntl (sock, F_SETFD, flags | FD_CLOEXEC)) ) | ||
321 | return 0; | ||
322 | #elif defined(MHD_WINSOCK_SOCKETS) | ||
323 | if (!SetHandleInformation ((HANDLE)sock, HANDLE_FLAG_INHERIT, 0)) | ||
324 | return 0; | ||
325 | #endif /* MHD_WINSOCK_SOCKETS */ | ||
326 | return !0; | ||
327 | } | ||