- an empty middle term in ?: violates ISO C
[oweals/busybox.git] / console-tools / chvt.c
index 4da0d6399520a659aaeb692a4abeea56fccf1e20..b1a429eb38ce21f1a233fb4d451fca5b9a67629a 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * Mini chvt implementation for busybox
  *
- * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,17 +36,15 @@ int chvt_main(int argc, char **argv)
 {
        int fd, num;
 
-       if ((argc != 2) || (**(argv + 1) == '-')) {
+       if (argc != 2) {
                bb_show_usage();
        }
 
        fd = get_console_fd();
-       num = atoi(argv[1]);
-       if (ioctl(fd, VT_ACTIVATE, num)) {
-               bb_perror_msg_and_die("VT_ACTIVATE");
-       }
-       if (ioctl(fd, VT_WAITACTIVE, num)) {
-               bb_perror_msg_and_die("VT_WAITACTIVE");
+       num =  bb_xgetlarg(argv[1], 10, 0, INT_MAX);
+       if((-1 == ioctl(fd, VT_ACTIVATE, num)) ||
+          (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
+               bb_perror_msg_and_die("ioctl");
        }
        return EXIT_SUCCESS;
 }