From b131ce006a3af81a1fc0510b9a36cfe3adebc5a8 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 11 Sep 2019 22:38:30 -0500 Subject: [PATCH] Update: documentation for f_pipe and add additional pipe functions Provide f_pipe_warning_exists(), f_pipe_error_exists(), and f_pipe_debug_exists(). In theory, the program should be able to grab data piped from any of these sources, if both the source exists and a way to pipe the source exists. --- level_0/f_pipe/c/pipe.c | 49 +++++++++++++++++++++++++++++++++++- level_0/f_pipe/c/pipe.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 111 insertions(+), 5 deletions(-) diff --git a/level_0/f_pipe/c/pipe.c b/level_0/f_pipe/c/pipe.c index 24dc45f..3e0e3b0 100644 --- a/level_0/f_pipe/c/pipe.c +++ b/level_0/f_pipe/c/pipe.c @@ -5,7 +5,6 @@ extern "C" { #endif #ifndef _di_f_pipe_exists_ - // returns f_true if the standard input contains piped data. f_return_status f_pipe_exists() { struct stat st_info; @@ -21,6 +20,54 @@ extern "C" { } #endif // _di_f_pipe_exists_ +#ifndef _di_f_pipe_warning_exists_ + f_return_status f_pipe_warning_exists() { + struct stat st_info; + + if (fstat(fileno(f_pipe_warning), &st_info) != 0) { + return f_status_set_error(f_file_stat_error); + } + + if (S_ISFIFO(st_info.st_mode)) { + return f_true; + } + + return f_false; + } +#endif // _di_f_pipe_warning_exists_ + +#ifndef _di_f_pipe_error_exists_ + f_return_status f_pipe_error_exists() { + struct stat st_info; + + if (fstat(fileno(f_pipe_error), &st_info) != 0) { + return f_status_set_error(f_file_stat_error); + } + + if (S_ISFIFO(st_info.st_mode)) { + return f_true; + } + + return f_false; + } +#endif // _di_f_pipe_error_exists_ + +#ifndef _di_f_pipe_debug_exists_ + f_return_status f_pipe_debug_exists() { + struct stat st_info; + + if (fstat(fileno(f_pipe_debug), &st_info) != 0) { + return f_status_set_error(f_file_stat_error); + } + + if (S_ISFIFO(st_info.st_mode)) { + return f_true; + } + + return f_false; + } +#endif // _di_f_pipe_debug_exists_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_pipe/c/pipe.h b/level_0/f_pipe/c/pipe.h index 2fb27dd..fcaefc5 100644 --- a/level_0/f_pipe/c/pipe.h +++ b/level_0/f_pipe/c/pipe.h @@ -22,17 +22,76 @@ extern "C" { #endif +/** + * Default pipe sources. + */ #ifndef _di_f_pipe_ - #define f_pipe f_standard_input + #define f_pipe f_standard_input + #define f_pipe_warning f_standard_warning + #define f_pipe_error f_standard_error + #define f_pipe_debug f_standard_debug #endif // _di_f_pipe_ +/** + * Identify whether or not the default f_pipe source (generally standard input) contains piped data. + * + * @return + * f_true if there is piped data. + * f_false if there is no piped data. + * f_file_stat_error (with error bit) on stat() error. + * + * @see stat() + */ #ifndef _di_f_pipe_exists_ - /** - * returns f_true if the standard input contains piped data. - */ extern f_return_status f_pipe_exists(); #endif // _di_f_pipe_exists_ +/** + * Identify whether or not the default f_pipe_warning source (generally standard warning) contains piped data. + * + * For most systems, standard warning does not exist and instead maps to standard output. + * + * @return + * f_true if there is piped data. + * f_false if there is no piped data. + * f_file_stat_error (with error bit) on stat() error. + * + * @see stat() + */ +#ifndef _di_f_pipe_warning_exists_ + extern f_return_status f_pipe_warning_exists(); +#endif // _di_f_pipe_warning_exists_ + +/** + * Identify whether or not the default f_pipe_error source (generally standard error) contains piped data. + * + * @return + * f_true if there is piped data. + * f_false if there is no piped data. + * f_file_stat_error (with error bit) on stat() error. + * + * @see stat() + */ +#ifndef _di_f_pipe_error_exists_ + extern f_return_status f_pipe_error_exists(); +#endif // _di_f_pipe_error_exists_ + +/** + * Identify whether or not the default f_pipe_debug source (generally standard warning) contains piped data. + * + * For most systems, standard debug does not exist and instead maps to standard output. + * + * @return + * f_true if there is piped data. + * f_false if there is no piped data. + * f_file_stat_error (with error bit) on stat() error. + * + * @see stat() + */ +#ifndef _di_f_pipe_debug_exists_ + extern f_return_status f_pipe_debug_exists(); +#endif // _di_f_pipe_debug_exists_ + #ifdef __cplusplus } // extern "C" #endif -- 1.8.3.1