- if ((f = fopen(s, "r")) == NULL) {
- perror(s);
- 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);
- }
- }
+ f = xfopen(s, "r");
+ fgets(buf, 255, f);
+ fclose(f);
+ chomp(buf);
+ if (sethostname(buf, strlen(buf)) < 0)
+ perror_msg_and_die("sethostname");