wifi: Various cleanups

This commit is contained in:
Aaron Marcher 2018-05-02 08:49:06 +02:00
parent 709549b4bd
commit f7a6d6c8f7
1 changed files with 6 additions and 9 deletions

View File

@ -25,20 +25,17 @@
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/net/", iface, snprintf(path, sizeof(path), "%s%s%s", "/sys/class/net/", iface,
"/operstate"); "/operstate");
fp = fopen(path, "r"); if (!(fp = fopen(path, "r"))) {
if (fp == NULL) {
fprintf(stderr, "fopen '%s': %s\n", path, fprintf(stderr, "fopen '%s': %s\n", path,
strerror(errno)); strerror(errno));
return NULL; return NULL;
} }
p = fgets(status, 5, fp); if(!(p = fgets(status, 5, fp)) || strcmp(status, "up\n") != 0) {
fclose(fp);
if(!p || strcmp(status, "up\n") != 0) {
return NULL; return NULL;
} }
fclose(fp);
fp = fopen("/proc/net/wireless", "r"); if (!(fp = fopen("/proc/net/wireless", "r"))) {
if (fp == NULL) {
fprintf(stderr, "fopen '/proc/net/wireless': %s\n", fprintf(stderr, "fopen '/proc/net/wireless': %s\n",
strerror(errno)); strerror(errno));
return NULL; return NULL;
@ -92,7 +89,7 @@
if (strcmp(id, "") == 0) if (strcmp(id, "") == 0)
return NULL; return NULL;
else
return id; return id;
} }
#elif defined(__OpenBSD__) #elif defined(__OpenBSD__)