From 2ca70d00ec9b4486bca372873041c9e0233d36c4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 4 Aug 2008 17:11:41 +0200 Subject: [PATCH] Move valid_fd_012() from string.c to fd.c. --- fd.c | 21 +++++++++++++++++++++ fd.h | 1 + string.c | 21 --------------------- string.h | 1 - 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fd.c b/fd.c index 58851723..8fc1abad 100644 --- a/fd.c +++ b/fd.c @@ -426,3 +426,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 752fb8f9..c73ec1e6 100644 --- a/string.c +++ b/string.c @@ -327,27 +327,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 *); -- 2.30.2