diff mbox series

teach sparse about '-o FILE'

Message ID 20181119233400.2092-1-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series teach sparse about '-o FILE' | expand

Commit Message

Luc Van Oostenryck Nov. 19, 2018, 11:34 p.m. UTC
sparse knows about the '-o FILE' option, parses it
but does nothing with it.

Change this by redirecting stdout to FILE.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/lib.c b/lib.c
index 07a5b9cda..ba5f1ffeb 100644
--- a/lib.c
+++ b/lib.c
@@ -23,6 +23,7 @@ 
  * THE SOFTWARE.
  */
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stddef.h>
@@ -673,6 +674,8 @@  static char **handle_switch_o(char *arg, char **next)
 	if (!strcmp (arg, "o")) {       // "-o foo"
 		if (!*++next)
 			die("argument to '-o' is missing");
+		if (!freopen(*next, "w", stdout))
+			die("error: cannot open %s: %s", *next, strerror(errno));
 	}
 	// else "-ofoo"