summaryrefslogtreecommitdiff
path: root/libc/inet/hostid.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 21:16:46 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-01 21:16:46 +0000
commitb0a365f74a0ac43fcbd53738844e577b2d9ec391 (patch)
tree262cc91ab047162f77df33a48891499434b56ca0 /libc/inet/hostid.c
parentfbb32ad9b6a4b6cffea1c5b4292b18c72cdadaf6 (diff)
hostid: improve extremely unreadable parts
*: remove checks of sigaction and sigprocmask results in cases where they clearly can't fail: sigaction(known_good_sig) sigprocmask(known_good_how) text data bss dec hex filename - 393 4 0 397 18d libc/pwd_grp/lckpwdf.o + 382 4 0 386 182 libc/pwd_grp/lckpwdf.o - 56 0 0 56 38 libc/signal/sigblock.o + 44 0 0 44 2c libc/signal/sigblock.o - 211 0 0 211 d3 libc/signal/sigset.o + 202 0 0 202 ca libc/signal/sigset.o - 56 0 0 56 38 libc/signal/sigsetmask.o + 44 0 0 44 2c libc/signal/sigsetmask.o - 309 0 0 309 135 libc/unistd/sleep.o + 256 0 0 256 100 libc/unistd/sleep.o
Diffstat (limited to 'libc/inet/hostid.c')
-rw-r--r--libc/inet/hostid.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/libc/inet/hostid.c b/libc/inet/hostid.c
index 42ee53fbd..cadcd1b28 100644
--- a/libc/inet/hostid.c
+++ b/libc/inet/hostid.c
@@ -33,11 +33,13 @@ int sethostid(long int new_id)
int fd;
int ret;
- if (geteuid() || getuid()) return __set_errno(EPERM);
- if ((fd=open(HOSTID,O_CREAT|O_WRONLY,0644))<0) return -1;
- ret = write(fd,(void *)&new_id,sizeof(new_id)) == sizeof(new_id)
- ? 0 : -1;
- close (fd);
+ if (geteuid() || getuid())
+ return __set_errno(EPERM);
+ fd = open(HOSTID, O_CREAT|O_WRONLY, 0644);
+ if (fd < 0)
+ return fd;
+ ret = write(fd, &new_id, sizeof(new_id)) == sizeof(new_id) ? 0 : -1;
+ close(fd);
return ret;
}
#endif
@@ -51,7 +53,8 @@ long int gethostid(void)
* It is not an error if we cannot read this file. It is not even an
* error if we cannot read all the bytes, we just carry on trying...
*/
- if ((fd=open(HOSTID,O_RDONLY))>=0 && read(fd,(void *)&id,sizeof(id)))
+ fd = open(HOSTID, O_RDONLY);
+ if (fd >= 0 && read(fd, &id, sizeof(id)))
{
close (fd);
return id;
@@ -69,7 +72,7 @@ long int gethostid(void)
* setting one anyway.
* Mitch
*/
- if (gethostname(host,MAXHOSTNAMELEN)>=0 && *host) {
+ if (gethostname(host, MAXHOSTNAMELEN) >= 0 && *host) {
struct hostent *hp;
struct in_addr in;
struct hostent ghbn_h;
@@ -84,21 +87,17 @@ long int gethostid(void)
/*if ((hp = gethostbyname(host)) == (struct hostent *)NULL)*/
gethostbyname_r(host, &ghbn_h, ghbn_buf, sizeof(ghbn_buf), &hp, &ghbn_errno);
- if (hp == (struct hostent *)NULL)
-
+ if (hp == NULL) {
/* This is not a error if we get here, as all it means is that
* this host is not on a network and/or they have not
* configured their network properly. So we return the unset
* hostid which should be 0, meaning that they should set it !!
*/
return 0;
- else {
- memcpy((char *) &in, (char *) hp->h_addr, hp->h_length);
-
- /* Just so it doesn't look exactly like the IP addr */
- return(in.s_addr<<16|in.s_addr>>16);
}
+ memcpy(&in, hp->h_addr, hp->h_length);
+ /* Just so it doesn't look exactly like the IP addr */
+ return (in.s_addr<<16 | in.s_addr>>16);
}
- else return 0;
-
+ return 0;
}