Imported Upstream version 2.0.90
[platform/upstream/kbd.git] / src / totextmode.c
index 3d59061..b5035c9 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * totextmode.c - aeb - 2000-01-20
  */
+#include "config.h"
+
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <linux/vt.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
-#include "getfd.h"
-#include "nls.h"
-#include "version.h"
 
-int
-main(int argc, char *argv[]) {
+#include "libcommon.h"
+
+int main(int argc, char *argv[])
+{
        int fd, num;
 
        set_progname(argv[0]);
-
-       setlocale(LC_ALL, "");
-       bindtextdomain(PACKAGE_NAME, LOCALEDIR);
-       textdomain(PACKAGE_NAME);
+       setuplocale();
 
        if (argc == 2 && !strcmp(argv[1], "-V"))
                print_version_and_exit();
 
        if (argc != 2) {
-               fprintf(stderr, _("usage: totextmode\n"));
-               exit(1);
+               kbd_error(EXIT_FAILURE, 0, _("usage: totextmode\n"));
        }
-       fd = getfd(NULL);
+
+       if ((fd = getfd(NULL)) < 0)
+               kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
+
        num = atoi(argv[1]);
-       if (ioctl(fd,KDSETMODE,KD_TEXT)) {
-               perror("totextmode: KDSETMODE");
-               exit(1);
+       if (ioctl(fd, KDSETMODE, KD_TEXT)) {
+               kbd_error(EXIT_FAILURE, errno, "totextmode: KDSETMODE");
        }
-       exit(0);
+       return EXIT_SUCCESS;
 }