diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_cmd.c | 18 | ||||
-rw-r--r-- | lib/utils_cmd.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index aaf055a9..5ba2f55e 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -45,6 +45,7 @@ #include "common.h" #include "utils_cmd.h" #include "utils_base.h" +#include <fcntl.h> #ifdef HAVE_SYS_WAIT_H # include <sys/wait.h> @@ -377,3 +378,20 @@ cmd_run_array (char *const *argv, output * out, output * err, int flags) return _cmd_close (fd); } + +int +cmd_file_read ( char *filename, output *out, int flags) +{ + int fd; + if(out) + memset (out, 0, sizeof(output)); + + if ((fd = open(filename, O_RDONLY)) == -1) { + die( STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno) ); + } + + if(out) + out->lines = _cmd_fetch_output (fd, out, flags); + + return 0; +} diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index d54b2b4d..8ebb5894 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h @@ -22,6 +22,7 @@ typedef struct output output; /** prototypes **/ int cmd_run (const char *, output *, output *, int); int cmd_run_array (char *const *, output *, output *, int); +int cmd_file_read (char *, output *, int); /* only multi-threaded plugins need to bother with this */ void cmd_init (void); |