diff options
author | Matt Kraai <kraai@debian.org> | 2000-09-27 06:43:35 +0400 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-09-27 06:43:35 +0400 |
commit | bbaef66b3f99213f06adf04df6b3e5e61278d75b (patch) | |
tree | 3838db4158e8e05a753fffd6e87cbbc7946425ad /networking/hostname.c | |
parent | e0bcce09baff576b1b16b3ffe780b6d91c7710c2 (diff) |
Consolidate handling of some fopen failures.
Diffstat (limited to 'networking/hostname.c')
-rw-r--r-- | networking/hostname.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/networking/hostname.c b/networking/hostname.c index 4320a968c..16a28ca43 100644 --- a/networking/hostname.c +++ b/networking/hostname.c @@ -1,6 +1,6 @@ /* vi: set sw=4 ts=4: */ /* - * $Id: hostname.c,v 1.13 2000/09/25 21:45:57 andersen Exp $ + * $Id: hostname.c,v 1.14 2000/09/27 02:43:35 kraai Exp $ * Mini hostname implementation for busybox * * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> @@ -46,18 +46,14 @@ void do_sethostname(char *s, int isfile) exit(1); } } else { - if ((f = fopen(s, "r")) == NULL) { - perror(s); + f = xfopen(s, "r"); + fgets(buf, 255, f); + fclose(f); + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = 0; + if (sethostname(buf, strlen(buf)) < 0) { + perror("sethostname"); exit(1); - } else { - fgets(buf, 255, f); - fclose(f); - if (buf[strlen(buf) - 1] == '\n') - buf[strlen(buf) - 1] = 0; - if (sethostname(buf, strlen(buf)) < 0) { - perror("sethostname"); - exit(1); - } } } } |