Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifieee80211.c
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <stddef.h> /* NB: for offsetof */ | #include <stddef.h> /* NB: for offsetof */ | ||||
#include <locale.h> | |||||
#include <langinfo.h> | |||||
#include "ifconfig.h" | #include "ifconfig.h" | ||||
#include <lib80211/lib80211_regdomain.h> | #include <lib80211/lib80211_regdomain.h> | ||||
#include <lib80211/lib80211_ioctl.h> | #include <lib80211/lib80211_ioctl.h> | ||||
#ifndef IEEE80211_FIXED_RATE_NONE | #ifndef IEEE80211_FIXED_RATE_NONE | ||||
#define IEEE80211_FIXED_RATE_NONE 0xff | #define IEEE80211_FIXED_RATE_NONE 0xff | ||||
▲ Show 20 Lines • Show All 5,277 Lines • ▼ Show 20 Lines | #undef tohex | ||||
return val; | return val; | ||||
} | } | ||||
static void | static void | ||||
print_string(const u_int8_t *buf, int len) | print_string(const u_int8_t *buf, int len) | ||||
{ | { | ||||
int i; | int i; | ||||
int hasspc; | int hasspc; | ||||
int utf8; | |||||
i = 0; | i = 0; | ||||
hasspc = 0; | hasspc = 0; | ||||
setlocale(LC_CTYPE, ""); | |||||
utf8 = strncmp("UTF-8", nl_langinfo(CODESET), 5) == 0; | |||||
kevans: Please do flip this around so that either `utf8` actually reflects that the current codeset is… | |||||
for (; i < len; i++) { | for (; i < len; i++) { | ||||
if (!isprint(buf[i]) && buf[i] != '\0') | if (!isprint(buf[i]) && buf[i] != '\0' && utf8) | ||||
break; | break; | ||||
if (isspace(buf[i])) | if (isspace(buf[i])) | ||||
hasspc++; | hasspc++; | ||||
} | } | ||||
if (i == len) { | if (i == len || utf8) { | ||||
if (hasspc || len == 0 || buf[0] == '\0') | if (hasspc || len == 0 || buf[0] == '\0') | ||||
printf("\"%.*s\"", len, buf); | printf("\"%.*s\"", len, buf); | ||||
else | else | ||||
printf("%.*s", len, buf); | printf("%.*s", len, buf); | ||||
} else { | } else { | ||||
printf("0x"); | printf("0x"); | ||||
for (i = 0; i < len; i++) | for (i = 0; i < len; i++) | ||||
printf("%02x", buf[i]); | printf("%02x", buf[i]); | ||||
▲ Show 20 Lines • Show All 372 Lines • Show Last 20 Lines |
Please do flip this around so that either utf8 actually reflects that the current codeset is UTF-8 and the rest of the logic later is inverted, or rename this to not_utf8 or something to that effect -- though I would kind of prefer the former.