1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-23 04:54:04 +02:00

Minor cleanup: better usage of fscanf.

Instead of having fscanf() read into a string buffer (with the risk of
overflowing it if sysfs returns an unexpectedly long string) and converting
the value to integer with atoi() afterwards, just use fscanf() to read
an integer.
This commit is contained in:
Maarten ter Huurne 2011-09-23 01:23:53 +02:00
parent 799bb13f0f
commit 84ec66c7ce

View File

@ -2017,10 +2017,8 @@ unsigned short GMenu2X::getBatteryLevel() {
#else #else
if (!batteryHandle) return 0; if (!batteryHandle) return 0;
int battval = 0; int battval = 0;
char battvalcstr[5]; fscanf(batteryHandle, "%d", &battval);
fscanf(batteryHandle, "%s", &battvalcstr[0]);
rewind(batteryHandle); rewind(batteryHandle);
battval = atoi(battvalcstr);
if (battval>90) return 5; if (battval>90) return 5;
if (battval>70) return 4; if (battval>70) return 4;
if (battval>50) return 3; if (battval>50) return 3;
@ -2029,10 +2027,8 @@ unsigned short GMenu2X::getBatteryLevel() {
if (!usbHandle) return 0; if (!usbHandle) return 0;
int usbval = 0; int usbval = 0;
char usbvalcstr[5]; fscanf(usbHandle, "%d", &usbval);
fscanf(usbHandle, "%s", &usbvalcstr[0]);
rewind(usbHandle); rewind(usbHandle);
usbval = atoi(usbvalcstr);
if (usbval==1) return 6; if (usbval==1) return 6;
return 0; return 0;