Within the components, snprintf() was unchecked and had inefficient
calls in some places.
We implement esnprintf() that does all the dirty laundry for us
and use it exclusively now.
implemented the netspeed functionality for openbsd.
furthermore the static keyword was removed of the interval variable in
config.def.h for usage as extern variable.
when an AC is connected apm_info shows a non-valid value for remaining
minutes. it was decided that in that case the function should return an
empty string.
Implementation of a battery_remaining function which returns the
remaining battery time in HH:MM format. Linux function still needs
implementation.
Move common code to load_apm_power_info
Given slstatus is a tool that runs in the background, most likely run
from .xinitrc, it's important to prepend the name of the tool to error
messages so it becomes clear where the error is coming from.
To make this much more consistent, this commit adds warn() and die()
utility functions consistent with other suckless projects and adapts all
calls to fprintf(stderr, *) to the warn() and die() functions, greatly
increasing the readability of the code.
1) Remove setlocale() (locales are harmful and any 'issues' shall
be fixed in different ways that are expected).
2) Disable buffering on stdout with setbuf() rather than flushing
it each time.
3) Make error messages more consistent.
4) Add error checks where applicable.
5) Make code a bit more readable where res is assigned.
6) Use XFlush() rather than XSync() (we don't need to wait for the
XServer to react, which could lead to long hangs on our side).
Posix guarantees that the resulting string is null-terminated, even if
we have an overflow. Instead of doing what has already been done,
properly warn when there has been an error or overflow, so the user can
do something about it.
The swapctl(2) function fills the swapent struct with 512KB blocks.
As we want to display in GB, i just modified the calculation for this to
get the expected output.
To reproduce the issue:
$ slstatus -s | tee
then it would print only when the stdout buffer is full, by block
of multiple lines.
fflush() makes sure the line is printed at every loop iteration