- move iprule and ipaddress from matches() to index_in_str_array
[oweals/busybox.git] / networking / hostname.c
index 6975b2b307250a07431702ae9be02304d80b4f7d..862bbdfa26afa021fef9bdd15d63e89f7cf561ad 100644 (file)
@@ -1,6 +1,5 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.36 2003/07/14 21:21:01 andersen Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -13,7 +12,7 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-#include "busybox.h"
+#include "libbb.h"
 
 static void do_sethostname(char *s, int isfile)
 {
@@ -30,18 +29,20 @@ static void do_sethostname(char *s, int isfile)
                }
        } else {
                f = xfopen(s, "r");
-               while (fgets(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), f) != NULL) {
-                       if (bb_common_bufsiz1[0] == '#') {
+#define strbuf bb_common_bufsiz1
+               while (fgets(strbuf, sizeof(strbuf), f) != NULL) {
+                       if (strbuf[0] == '#') {
                                continue;
                        }
-                       chomp(bb_common_bufsiz1);
-                       do_sethostname(bb_common_bufsiz1, 0);
+                       chomp(strbuf);
+                       do_sethostname(strbuf, 0);
                }
                if (ENABLE_FEATURE_CLEAN_UP)
                        fclose(f);
        }
 }
 
+int hostname_main(int argc, char **argv);
 int hostname_main(int argc, char **argv)
 {
        enum {
@@ -49,11 +50,12 @@ int hostname_main(int argc, char **argv)
                OPT_f = 0x2,
                OPT_i = 0x4,
                OPT_s = 0x8,
+               OPT_F = 0x10,
                OPT_dfis = 0xf,
        };
 
        char buf[256];
-       char *hostname_str = NULL;
+       char *hostname_str;
 
        if (argc < 1)
                bb_show_usage();
@@ -71,7 +73,7 @@ int hostname_main(int argc, char **argv)
                        puts(hp->h_name);
                } else if (option_mask32 & OPT_s) {
                        if (p != NULL) {
-                               *p = 0;
+                               *p = '\0';
                        }
                        puts(hp->h_name);
                } else if (option_mask32 & OPT_d) {
@@ -85,7 +87,7 @@ int hostname_main(int argc, char **argv)
                }
        }
        /* Set the hostname */
-       else if (hostname_str != NULL) {
+       else if (option_mask32 & OPT_F) {
                do_sethostname(hostname_str, 1);
        } else if (optind < argc) {
                do_sethostname(argv[optind], 0);