From: Andre Noll Date: Fri, 9 Jan 2009 00:16:44 +0000 (+0100) Subject: Merge commit 'meins/master' X-Git-Tag: v0.3.4~75^2~35 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=40de1dd2fdbb054444d585aa70e2d50166a66e07;hp=07dd05be81f44b0af666a8bccf0a19ffff371db1 Merge commit 'meins/master' --- diff --git a/fd.c b/fd.c index d0b5c895..c675aaff 100644 --- a/fd.c +++ b/fd.c @@ -427,3 +427,24 @@ again: goto again; return ret; } + +/** + * Ensure that file descriptors 0, 1, and 2 are valid. + * + * Common approach that opens /dev/null until it gets a file descriptor greater + * than two. + * + * \sa okir's Black Hats Manual. + */ +void valid_fd_012(void) +{ + while (1) { + int fd = open("/dev/null", O_RDWR); + if (fd < 0) + exit(EXIT_FAILURE); + if (fd > 2) { + close(fd); + break; + } + } +} diff --git a/fd.h b/fd.h index 22141be2..ae692b4f 100644 --- a/fd.h +++ b/fd.h @@ -24,3 +24,4 @@ int mmap_full_file(const char *filename, int open_mode, void **map, size_t *size, int *fd_ptr); int para_munmap(void *start, size_t length); int write_ok(int fd); +void valid_fd_012(void); diff --git a/string.c b/string.c index d23e43c1..bdc113d3 100644 --- a/string.c +++ b/string.c @@ -328,27 +328,6 @@ __must_check unsigned split_args(char *args, char *** const argv_ptr, const char return n; } -/** - * Ensure that file descriptors 0, 1, and 2 are valid. - * - * Common approach that opens /dev/null until it gets a file descriptor greater - * than two. - * - * \sa okir's Black Hats Manual. - */ -void valid_fd_012(void) -{ - while (1) { - int fd = open("/dev/null", O_RDWR); - if (fd < 0) - exit(EXIT_FAILURE); - if (fd > 2) { - close(fd); - break; - } - } -} - /** * Get the own hostname. * diff --git a/string.h b/string.h index 561ff4e8..e91a140b 100644 --- a/string.h +++ b/string.h @@ -40,7 +40,6 @@ __must_check __malloc char *para_logname(void); __must_check __malloc char *para_homedir(void); __must_check unsigned split_args(char *args, char *** const argv_ptr, const char *delim); __malloc char *para_hostname(void); -void valid_fd_012(void); __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...); /** Used for for_each_line() and for_each_line_ro(). */ typedef int line_handler_t(char *, void *);