We don't need the fd=fd hack for GCC 3.4 in 2021, and <linux/vt.h> has
given names to the two magic numbers since at least Linux 2.4.0...
---
 toys/other/chvt.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
From 7529694f866121f1549c1aee4eea5dafb4e97528 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Fri, 24 Sep 2021 17:07:29 -0700
Subject: [PATCH] chvt: remove old workarounds.

We don't need the fd=fd hack for GCC 3.4 in 2021, and <linux/vt.h> has
given names to the two magic numbers since at least Linux 2.4.0...
---
 toys/other/chvt.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/toys/other/chvt.c b/toys/other/chvt.c
index a93327fb..7d69f9a4 100644
--- a/toys/other/chvt.c
+++ b/toys/other/chvt.c
@@ -18,17 +18,16 @@ config CHVT
 */
 
 #include "toys.h"
+#include <linux/vt.h>
 
 void chvt_main(void)
 {
-  int vtnum, fd = fd;
+  int vt, fd;
   char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc;
 
-  vtnum=atoi(*toys.optargs);
-  for (cc = consoles; *cc; cc++)
-    if (-1 != (fd = open(*cc, O_RDWR))) break;
+  vt = atoi(*toys.optargs);
+  for (cc = consoles; *cc; cc++) if ((fd = open(*cc, O_RDWR)) != -1) break;
 
-  // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h
-  if (!*cc || fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
+  if (fd == -1 || ioctl(fd, VT_ACTIVATE, vt) || ioctl(fd, VT_WAITACTIVE, vt))
     perror_exit(0);
 }
-- 
2.33.0.685.g46640cef36-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to