svn commit: trunk/busybox/networking

aldot at busybox.net aldot at busybox.net
Tue Jan 9 10:06:19 UTC 2007


Author: aldot
Date: 2007-01-09 02:06:19 -0800 (Tue, 09 Jan 2007)
New Revision: 17204

Log:
vda, we once had a get_chomped_line_from_file or the like. Where is that nowadays? FIXME: use it here instead of the fgets()
- shrink by ~9%: use common_buf, reuse are_you_root, adopt to global option_mask32


Modified:
   trunk/busybox/networking/hostname.c


Changeset:
Modified: trunk/busybox/networking/hostname.c
===================================================================
--- trunk/busybox/networking/hostname.c	2007-01-08 23:55:33 UTC (rev 17203)
+++ trunk/busybox/networking/hostname.c	2007-01-09 10:06:19 UTC (rev 17204)
@@ -18,29 +18,27 @@
 static void do_sethostname(char *s, int isfile)
 {
 	FILE *f;
-	char buf[256];
 
 	if (!s)
 		return;
 	if (!isfile) {
 		if (sethostname(s, strlen(s)) < 0) {
 			if (errno == EPERM)
-				bb_error_msg_and_die("you must be root to change the hostname");
+				bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
 			else
 				bb_perror_msg_and_die("sethostname");
 		}
 	} else {
 		f = xfopen(s, "r");
-		while (fgets(buf, sizeof(buf), f) != NULL) {
-			if (buf[0] =='#') {
+		while (fgets(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), f) != NULL) {
+			if (bb_common_bufsiz1[0] == '#') {
 				continue;
 			}
-			chomp(buf);
-			do_sethostname(buf, 0);
+			chomp(bb_common_bufsiz1);
+			do_sethostname(bb_common_bufsiz1, 0);
 		}
-#ifdef CONFIG_FEATURE_CLEAN_UP
-		fclose(f);
-#endif
+		if (ENABLE_FEATURE_CLEAN_UP)
+			fclose(f);
 	}
 }
 
@@ -55,31 +53,31 @@
 	};
 
 	char buf[256];
-	unsigned opt;
 	char *hostname_str = NULL;
 
 	if (argc < 1)
 		bb_show_usage();
 
-	opt = getopt32(argc, argv, "dfisF:", &hostname_str);
+	getopt32(argc, argv, "dfisF:", &hostname_str);
 
 	/* Output in desired format */
-	if (opt & OPT_dfis) {
+	if (option_mask32 & OPT_dfis) {
 		struct hostent *hp;
 		char *p;
 		gethostname(buf, sizeof(buf));
 		hp = xgethostbyname(buf);
 		p = strchr(hp->h_name, '.');
-		if (opt & OPT_f) {
+		if (option_mask32 & OPT_f) {
 			puts(hp->h_name);
-		} else if (opt & OPT_s) {
+		} else if (option_mask32 & OPT_s) {
 			if (p != NULL) {
 				*p = 0;
 			}
 			puts(hp->h_name);
-		} else if (opt & OPT_d) {
-			if (p) puts(p + 1);
-		} else if (opt & OPT_i) {
+		} else if (option_mask32 & OPT_d) {
+			if (p)
+				puts(p + 1);
+		} else if (option_mask32 & OPT_i) {
 			while (hp->h_addr_list[0]) {
 				printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));
 			}




More information about the busybox-cvs mailing list