Oops. Since dirent.h depends on BB_FEATURE_SH_TAB_COMPLETION, put it
[oweals/busybox.git] / hostname.c
index b1f0613694a56d0b2f7ed67587efa652bd3fc067..e1486b3655a1b4508f315931607eff5ba200d989 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.20 2001/01/24 18:44:54 andersen Exp $
+ * $Id: hostname.c,v 1.24 2001/02/14 21:23:06 andersen Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -28,6 +28,7 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <unistd.h>
+#include <string.h>
 #include <stdio.h>
 
 void do_sethostname(char *s, int isfile)
@@ -40,7 +41,7 @@ void do_sethostname(char *s, int isfile)
        if (!isfile) {
                if (sethostname(s, strlen(s)) < 0) {
                        if (errno == EPERM)
-                               error_msg_and_die("you must be root to change the hostname\n");
+                               error_msg_and_die("you must be root to change the hostname");
                        else
                                perror_msg_and_die("sethostname");
                }
@@ -48,8 +49,7 @@ void do_sethostname(char *s, int isfile)
                f = xfopen(s, "r");
                fgets(buf, 255, f);
                fclose(f);
-               if (buf[strlen(buf) - 1] == '\n')
-                       buf[strlen(buf) - 1] = 0;
+               chomp(buf);
                if (sethostname(buf, strlen(buf)) < 0)
                        perror_msg_and_die("sethostname");
        }
@@ -66,7 +66,7 @@ int hostname_main(int argc, char **argv)
        char *s = NULL;
 
        if (argc < 1)
-               usage(hostname_usage);
+               show_usage();
 
        while (--argc > 0 && **(++argv) == '-') {
                while (*(++(*argv))) {
@@ -82,18 +82,18 @@ int hostname_main(int argc, char **argv)
                                break;
                        case 'F':
                                if (--argc == 0) {
-                                       usage(hostname_usage);
+                                       show_usage();
                                }
                                filename = *(++argv);
                                break;
                        case '-':
                                if (strcmp(++(*argv), "file") || --argc ==0 ) {
-                                       usage(hostname_usage);
+                                       show_usage();
                                }
                                filename = *(++argv);
                                break;
                        default:
-                               usage(hostname_usage);
+                               show_usage();
                        }
                        if (filename != NULL)
                                break;