mirror of
https://github.com/openwrt/packages.git
synced 2025-12-21 19:14:30 +04:00
The musl libc only implements POSIX basename() but provided a GNU header
kludge in <string.h>, which was removed in musl 1.2.5 [1]. Use the standard
<libgen.h> header to avoid compilation warnings like:
zabbix-6.4.7/zabbix-extra-mac80211/zabbix_helper_mac80211.c:37:11: warning:
implicit declaration of function 'basename' [-Wimplicit-function-declaration]
37 | phy = basename(phy);
| ^~~~~~~~
zabbix-6.4.7/zabbix-extra-mac80211/zabbix_helper_mac80211.c:37:9: warning:
assignment to 'char *' from 'int' makes pointer from integer without a cast
[-Wint-conversion]
37 | phy = basename(phy);
| ^
zabbix-6.4.7/zabbix-extra-mac80211/zabbix_helper_mac80211.c:38:10: warning:
assignment to 'char *' from 'int' makes pointer from integer without a cast
[-Wint-conversion]
38 | stat = basename(stat);
| ^
Link 1: https://git.musl-libc.org/cgit/musl/log/?qt=grep&q=basename
Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
79 lines
1.8 KiB
C
79 lines
1.8 KiB
C
#define _GNU_SOURCE
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <libgen.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
#include <stdbool.h>
|
|
|
|
int discovery()
|
|
{
|
|
DIR *dir;
|
|
struct dirent *ent;
|
|
bool comma = false;
|
|
if ((dir = opendir ("/sys/kernel/debug/ieee80211/")) != NULL) {
|
|
printf("{\"data\":[");
|
|
while ((ent = readdir (dir)) != NULL) {
|
|
if (strcmp(".", ent->d_name) && strcmp("..", ent->d_name)) {
|
|
if (comma)
|
|
printf(",");
|
|
printf("{\"{#PHY}\":\"%s\"}", ent->d_name);
|
|
comma = true;
|
|
}
|
|
}
|
|
printf("]}\n");
|
|
closedir(dir);
|
|
} else {
|
|
perror("");
|
|
return EXIT_FAILURE;
|
|
}
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
int get_param(char *phy, char *stat)
|
|
{
|
|
char *filename = NULL;
|
|
FILE *f = NULL;
|
|
phy = basename(phy);
|
|
stat = basename(stat);
|
|
if (asprintf(&filename, "/sys/kernel/debug/ieee80211/%s/statistics/%s", phy, stat) > 0)
|
|
f = fopen(filename, "r");
|
|
|
|
if (f != NULL) {
|
|
char temp[256];
|
|
while (fgets(temp, 256, f) != NULL)
|
|
printf("%s",temp);
|
|
|
|
fclose(f);
|
|
} else {
|
|
perror("");
|
|
return EXIT_FAILURE;
|
|
}
|
|
free(filename);
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
int usage(char *name)
|
|
{
|
|
fprintf(stderr, "Usage:\n");
|
|
fprintf(stderr, " %s discovery\n", name);
|
|
fprintf(stderr, " => print mac80211.phydiscovery discovery rule\n");
|
|
fprintf(stderr, " %s PHY STAT\n", name);
|
|
fprintf(stderr, " => cat /sys/kernel/debug/ieee80211/PHY/statistics/STAT as root\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
|
|
switch (argc) {
|
|
case 2:
|
|
return discovery();
|
|
case 3:
|
|
return get_param(argv[1], argv[2]);
|
|
default:
|
|
return usage(argv[0]);
|
|
}
|
|
}
|