diff --git a/src/debug.c b/src/debug.c index fdefd6706..ae7420fca 100644 --- a/src/debug.c +++ b/src/debug.c @@ -36,6 +36,7 @@ #include /* Standard input/output definitions */ #include /* String function definitions */ #include +#include #ifdef ANDROID # include @@ -326,4 +327,30 @@ FILE *HAMLIB_API rig_set_debug_file(FILE *stream) return prev_stream; } +/** + * \brief Change the output stream to a filename + * + * \param filename The filename to direct debugging output. + * + * \sa `FILE`(3) + */ +FILE *HAMLIB_API rig_set_debug_filename(char *filename) +{ + FILE *prev_stream = rig_debug_stream; + rig_debug(RIG_DEBUG_WARN, "%s: debug will stream to '%s'\n", __func__, + filename); + FILE *stream = fopen(filename, "w"); + + if (stream == NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s: error opening stream: %s\n", __func__, + strerror(errno)); + return NULL; + } + + rig_debug_stream = stream; + + return prev_stream; +} + /** @} */