There is no need to have a variable holding the interface name and
doing the exercise of stripping the trailing colon. It is enough
to just compare the line to check whether it contains the device
name. And only if it does we sscanf() its contents.
After a recent change in the kernel (their commit 6e094bd) my
wireless interface name is 8 characters long, wlp3s0b1. But
the wmnet code to read the received bytes
totalbytes_in = strtoul(&buffer[7], NULL, 10);
assumed that the interface name in /proc/net/dev would be 6 characters
long (and would start reading at position 7).
In the linux kernel mailing list I reported the regression and none
other than Al Viro replied,
> I am not sure if 'wmnet' could do this better (any suggestions?),
*snort*
well, yes - it's called scanf(). And if one is really, really nervous
about the overhead of <gasp> parsing a bunch of integers (as if fopen/
fgets/fclose alone won't cost enough to make constantly calling that
sucker a bad idea), just use ptr + <something> - 6 instead of
&buffer[<something>] in there. That thing has just found where the
colon was (and replaced it with NUL), so dealing with "the first field
turned out to be too long and shifted everything past it" isn't hard.
******
I also took the oportunity to remove the unused variables diffpackets_{in,out}
Drop "-p -o root -g root" from the INSTALL_* Makefile variables and honor
the CONF Makefile variable for accessing the global config file instead of
hardcoding it as /etc.
These changes allow users without root access to install wmcalc in their home
directory.
In particular,
- Drop INCLUDES and LIBINC variables; referenced deprecated X11R6 directories
and INCLUDES unnecessarily included the default path.
- Switch hard-coded gcc for CC variable.
- Move hard-coded -02 and -Wall flags to new CFLAGS variable.
- Switch ${} to $() for consistency.
- Add new INSTALL_DIR variable for creating installation directories.
- Respect CPPFLAGS and LDFLAGS.
To simplify maintenace, all references to the current version number outside
of the appropriate macro in in wmtime.c have been removed. Note that this
macro had been WMMON_VERSION, likely a copy/paste error, and has been
renamed to WMTIME_VERSION.
In particular,
- Remove reference to deprecated X11R6 directory.
- Honor PREFIX and INSTALL variables.
- Change definition of CFLAGS from += to =; perhaps users don't want to
append -O2. Also move -Wall to CFLAGS.
- Use C*FLAGS only when compiling and LDFLAGS only when linking.
- Create directories if needed during install.
- Install manpage.
Previously, wmitime only had support for English, French, and (in Debian
only) Hungarian. In addition, the choice was made at compile time.
This patch adds run-time support for any language using the Latin alphabet.
The locale is determined by the user's environment or may be specified on
the command line with the "-l" option. Note that users whose environment
specifies a non-Latin locale may wish to use, e.g., "-l C", as otherwise
no date will appear.
Note that, for simplicity, the month and day are now displayed as "01 JAN"
as opposed to "JAN 01". (Previously, the former format was used for English
and the latter for French.)
Previously, release history was kept in README. This has been separated out
into a new file to avoid a "no-upstream-changelog" Lintian warning in the
Debian package.
In particular, fix warnings of the form "warning: ignoring return value of
‘char* fgets(char*, int, FILE*)’, declared with attribute warn_unused_result" by
checking return value of fgets.