summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5281429)
* strncmp(s1, s2, strlen(s2)) → BEGINS_WITH(s1, s2)
* strncmp(s1, s2, strlen(s1)) → strcmp(s1, s2)
* Prefer case-insensitive comparison for options
seconds -= (minutes * 60);
if (status == CS_DISCHARGING && low_threshold > 0) {
seconds -= (minutes * 60);
if (status == CS_DISCHARGING && low_threshold > 0) {
- if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+ if (strcasecmp(threshold_type, "percentage") == 0
&& percentage_remaining < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& percentage_remaining < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
- } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0
+ } else if (strcasecmp(threshold_type, "time") == 0
&& seconds_remaining < 60 * low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& seconds_remaining < 60 * low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
* we colorize the output if threshold_type is set to percentage
* (since we don't have any information on remaining time). */
if (status == CS_DISCHARGING && low_threshold > 0) {
* we colorize the output if threshold_type is set to percentage
* (since we don't have any information on remaining time). */
if (status == CS_DISCHARGING && low_threshold > 0) {
- if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+ if (strcasecmp(threshold_type, "percentage") == 0
&& percentage_remaining < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& percentage_remaining < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
minutes -= (hours * 60);
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d",
max(hours, 0), max(minutes, 0));
minutes -= (hours * 60);
(void)snprintf(remainingbuf, sizeof(remainingbuf), "%02dh%02d",
max(hours, 0), max(minutes, 0));
- if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+ if (strcasecmp(threshold_type, "percentage") == 0
&& present_rate < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& present_rate < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
- } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0
+ } else if (strcasecmp(threshold_type, "time") == 0
&& remaining < (u_int) low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& remaining < (u_int) low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
if (status == CS_DISCHARGING && low_threshold > 0) {
(void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
if (status == CS_DISCHARGING && low_threshold > 0) {
- if (strncmp(threshold_type, "percentage", strlen(threshold_type)) == 0
+ if (strcasecmp(threshold_type, "percentage") == 0
&& apm_info.battery_life < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& apm_info.battery_life < low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
- } else if (strncmp(threshold_type, "time", strlen(threshold_type)) == 0
+ } else if (strcasecmp(threshold_type, "time") == 0
&& apm_info.minutes_left < (u_int) low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
&& apm_info.minutes_left < (u_int) low_threshold) {
START_COLOR("color_bad");
colorful_output = true;
- if (strncmp(walk+1, "status", strlen("status")) == 0) {
+ if (BEGINS_WITH(walk+1, "status")) {
outwalk += sprintf(outwalk, "%s", statusbuf);
walk += strlen("status");
outwalk += sprintf(outwalk, "%s", statusbuf);
walk += strlen("status");
- } else if (strncmp(walk+1, "percentage", strlen("percentage")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "percentage")) {
outwalk += sprintf(outwalk, "%s", percentagebuf);
walk += strlen("percentage");
outwalk += sprintf(outwalk, "%s", percentagebuf);
walk += strlen("percentage");
- } else if (strncmp(walk+1, "remaining", strlen("remaining")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "remaining")) {
outwalk += sprintf(outwalk, "%s", remainingbuf);
walk += strlen("remaining");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(remainingbuf);
outwalk += sprintf(outwalk, "%s", remainingbuf);
walk += strlen("remaining");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(remainingbuf);
- } else if (strncmp(walk+1, "emptytime", strlen("emptytime")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "emptytime")) {
outwalk += sprintf(outwalk, "%s", emptytimebuf);
walk += strlen("emptytime");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(emptytimebuf);
outwalk += sprintf(outwalk, "%s", emptytimebuf);
walk += strlen("emptytime");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(emptytimebuf);
- } else if (strncmp(walk+1, "consumption", strlen("consumption")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "consumption")) {
outwalk += sprintf(outwalk, "%s", consumptionbuf);
walk += strlen("consumption");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(consumptionbuf);
outwalk += sprintf(outwalk, "%s", consumptionbuf);
walk += strlen("consumption");
EAT_SPACE_FROM_OUTPUT_IF_EMPTY(consumptionbuf);
goto error;
}
/* 'path' is the node within the full path (defaults to acpitz0). */
goto error;
}
/* 'path' is the node within the full path (defaults to acpitz0). */
- if (strncmp(sensordev.xname, thermal_zone, strlen(thermal_zone)) == 0) {
+ if (BEGINS_WITH(sensordev.xname, thermal_zone)) {
mib[3] = SENSOR_TEMP;
/* Limit to temo0, but should retrieve from a full path... */
for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) {
mib[3] = SENSOR_TEMP;
/* Limit to temo0, but should retrieve from a full path... */
for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) {
- if (strncmp(walk+1, "usage", strlen("usage")) == 0) {
+ if (BEGINS_WITH(walk+1, "usage")) {
outwalk += sprintf(outwalk, "%02d%%", diff_usage);
walk += strlen("usage");
}
outwalk += sprintf(outwalk, "%02d%%", diff_usage);
walk += strlen("usage");
}
*
*/
static int print_bytes_human(char *outwalk, uint64_t bytes, const char *prefix_type) {
*
*/
static int print_bytes_human(char *outwalk, uint64_t bytes, const char *prefix_type) {
- if (strncmp(prefix_type, "decimal", strlen(prefix_type)) == 0) {
+ if (strcasecmp(prefix_type, "decimal") == 0) {
return format_bytes(outwalk, bytes, DECIMAL_BASE, si_symbols);
return format_bytes(outwalk, bytes, DECIMAL_BASE, si_symbols);
- } else if (strncmp(prefix_type, "custom", strlen(prefix_type)) == 0) {
+ } else if (strcasecmp(prefix_type, "custom") == 0) {
return format_bytes(outwalk, bytes, BINARY_BASE, custom_symbols);
} else {
return format_bytes(outwalk, bytes, BINARY_BASE, iec_symbols);
return format_bytes(outwalk, bytes, BINARY_BASE, custom_symbols);
} else {
return format_bytes(outwalk, bytes, BINARY_BASE, iec_symbols);
* Skip these non-informative values and go right ahead to the
* actual speeds.
*/
* Skip these non-informative values and go right ahead to the
* actual speeds.
*/
- if (strncmp(desc->ifmt_string, "autoselect", strlen("autoselect")) == 0 ||
- strncmp(desc->ifmt_string, "auto", strlen("auto")) == 0)
+ if (BEGINS_WITH(desc->ifmt_string, "autoselect") ||
+ BEGINS_WITH(desc->ifmt_string, "auto"))
continue;
if (IFM_TYPE_MATCH(desc->ifmt_word, ifmr.ifm_active) &&
continue;
if (IFM_TYPE_MATCH(desc->ifmt_word, ifmr.ifm_active) &&
- if (strncmp(walk+1, "ip", strlen("ip")) == 0) {
+ if (BEGINS_WITH(walk+1, "ip")) {
outwalk += sprintf(outwalk, "%s", ip_address);
walk += strlen("ip");
outwalk += sprintf(outwalk, "%s", ip_address);
walk += strlen("ip");
- } else if (strncmp(walk+1, "speed", strlen("speed")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "speed")) {
outwalk += print_eth_speed(outwalk, interface);
walk += strlen("speed");
}
outwalk += print_eth_speed(outwalk, interface);
walk += strlen("speed");
}
- if (strncmp(walk+1, "ip", strlen("ip")) == 0) {
+ if (BEGINS_WITH(walk+1, "ip")) {
outwalk += sprintf(outwalk, "%s", addr_string);
walk += strlen("ip");
}
outwalk += sprintf(outwalk, "%s", addr_string);
walk += strlen("ip");
}
- if (strncmp(walk+1, "title", strlen("title")) == 0) {
+ if (BEGINS_WITH(walk+1, "title")) {
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
- } else if (strncmp(walk+1, "status", strlen("status")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "status")) {
outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
walk += strlen("status");
}
outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
walk += strlen("status");
}
- if (strncmp(walk+1, "title", strlen("title")) == 0) {
+ if (BEGINS_WITH(walk+1, "title")) {
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
outwalk += sprintf(outwalk, "%s", title);
walk += strlen("title");
- } else if (strncmp(walk+1, "status", strlen("status")) == 0) {
+ } else if (BEGINS_WITH(walk+1, "status")) {
outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
walk += strlen("status");
}
outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
walk += strlen("status");
}