diff options
author | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-09-27 02:43:35 +0000 |
---|---|---|
committer | kraai <kraai@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-09-27 02:43:35 +0000 |
commit | 883ad0f7f5341134101a74d230445d6ed704a914 (patch) | |
tree | 3838db4158e8e05a753fffd6e87cbbc7946425ad /networking | |
parent | 8a0593d4ba17298f272ffeaa00c70e4a67355c74 (diff) | |
download | busybox-w32-883ad0f7f5341134101a74d230445d6ed704a914.tar.gz busybox-w32-883ad0f7f5341134101a74d230445d6ed704a914.tar.bz2 busybox-w32-883ad0f7f5341134101a74d230445d6ed704a914.zip |
Consolidate handling of some fopen failures.
git-svn-id: svn://busybox.net/trunk/busybox@1136 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'networking')
-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 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * $Id: hostname.c,v 1.13 2000/09/25 21:45:57 andersen Exp $ | 3 | * $Id: hostname.c,v 1.14 2000/09/27 02:43:35 kraai Exp $ |
4 | * Mini hostname implementation for busybox | 4 | * Mini hostname implementation for busybox |
5 | * | 5 | * |
6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 6 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -46,18 +46,14 @@ void do_sethostname(char *s, int isfile) | |||
46 | exit(1); | 46 | exit(1); |
47 | } | 47 | } |
48 | } else { | 48 | } else { |
49 | if ((f = fopen(s, "r")) == NULL) { | 49 | f = xfopen(s, "r"); |
50 | perror(s); | 50 | fgets(buf, 255, f); |
51 | fclose(f); | ||
52 | if (buf[strlen(buf) - 1] == '\n') | ||
53 | buf[strlen(buf) - 1] = 0; | ||
54 | if (sethostname(buf, strlen(buf)) < 0) { | ||
55 | perror("sethostname"); | ||
51 | exit(1); | 56 | exit(1); |
52 | } else { | ||
53 | fgets(buf, 255, f); | ||
54 | fclose(f); | ||
55 | if (buf[strlen(buf) - 1] == '\n') | ||
56 | buf[strlen(buf) - 1] = 0; | ||
57 | if (sethostname(buf, strlen(buf)) < 0) { | ||
58 | perror("sethostname"); | ||
59 | exit(1); | ||
60 | } | ||
61 | } | 57 | } |
62 | } | 58 | } |
63 | } | 59 | } |