Xinqi Bao's Git

entropy: Port to OpenBSD
[slstatus.git] / components / wifi.c
index 33e09b7..c209598 100644 (file)
@@ -25,8 +25,7 @@
 
                snprintf(path, sizeof(path), "%s%s%s", "/sys/class/net/", iface,
                         "/operstate");
-               fp = fopen(path, "r");
-               if (fp == NULL) {
+               if (!(fp = fopen(path, "r"))) {
                        fprintf(stderr, "fopen '%s': %s\n", path,
                                strerror(errno));
                        return NULL;
@@ -37,8 +36,7 @@
                        return NULL;
                }
 
-               fp = fopen("/proc/net/wireless", "r");
-               if (fp == NULL) {
+               if (!(fp = fopen("/proc/net/wireless", "r"))) {
                        fprintf(stderr, "fopen '/proc/net/wireless': %s\n",
                                strerror(errno));
                        return NULL;
                                break;
                }
                fclose(fp);
-               if (i < 2 || !p)
+               if (i < 2 || !p) {
                        return NULL;
+               }
 
-               if ((datastart = strstr(buf, iface)) == NULL)
+               if (!(datastart = strstr(buf, iface))) {
                        return NULL;
+               }
 
                datastart = (datastart+(strlen(iface)+1));
                sscanf(datastart + 1, " %*d   %d  %*d  %*d\t\t  %*d\t   "
                wreq.u.essid.length = IW_ESSID_MAX_SIZE+1;
                snprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", iface);
 
-               if (sockfd == -1) {
+               if (sockfd < 0) {
                        fprintf(stderr, "socket 'AF_INET': %s\n",
                                strerror(errno));
                        return NULL;
                }
                wreq.u.essid.pointer = id;
-               if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) {
-                       fprintf(stderr, "ioctl 'SIOCGIWESSID': %s\n",
-                               strerror(errno));
+               if (ioctl(sockfd,SIOCGIWESSID, &wreq) < 0) {
+                       fprintf(stderr, "ioctl 'SIOCGIWESSID': %s\n", strerror(errno));
                        close(sockfd);
                        return NULL;
                }
 
                close(sockfd);
 
-               if (strcmp(id, "") == 0)
+               if (!strcmp(id, "")) {
                        return NULL;
-               else
-                       return id;
+               }
+
+               return id;
        }
 #elif defined(__OpenBSD__)
        /* unimplemented */