all repos — tint2 @ b5578ff5bc3302b975e0f1418ef778d9168dc73c

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

battery: Do not redefine strncat with different semantics
o9000 mrovi9000@gmail.com
commit

b5578ff5bc3302b975e0f1418ef778d9168dc73c

parent

f9ad3cb02977c5b3c675092e34436125c7cef73d

1 files changed, 11 insertions(+), 10 deletions(-)

jump to
M src/battery/battery.csrc/battery/battery.c

@@ -128,7 +128,8 @@

battery_os_free(); } -char *strncat(char *dest, const char *addendum, size_t limit) +// Appends addendum to dest, and does not allow dest to grow over limit (including NULL terminator). +char *strnappend(char *dest, const char *addendum, size_t limit) { char *tmp = strdup(dest);

@@ -164,7 +165,7 @@ o++; // Skip the format control character.

switch (*c) { case 's': // Append the appropriate status message to the string. - strncat(dest, + strnappend(dest, (battery_state.state == BATTERY_CHARGING) ? "Charging" : (battery_state.state == BATTERY_DISCHARGING)

@@ -174,38 +175,38 @@ BATTERY_BUF_SIZE);

break; case 'm': snprintf(buf, sizeof(buf), "%02d", battery_state.time.minutes); - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); break; case 'h': snprintf(buf, sizeof(buf), "%02d", battery_state.time.hours); - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); break; case 'p': snprintf(buf, sizeof(buf), "%d%%", battery_state.percentage); - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); break; case 't': if (battery_state.state == BATTERY_FULL) { snprintf(buf, sizeof(buf), "Full"); - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); } else { snprintf(buf, sizeof(buf), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); } break; case '%': case '\0': - strncat(dest, "%", BATTERY_BUF_SIZE); + strnappend(dest, "%", BATTERY_BUF_SIZE); break; default: fprintf(stderr, "Battery: unrecognised format specifier '%%%c'.\n", *c); buf[0] = *c; - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); } } else { buf[0] = *c; - strncat(dest, buf, BATTERY_BUF_SIZE); + strnappend(dest, buf, BATTERY_BUF_SIZE); } } }