mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-23 00:43:09 +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:
parent
799bb13f0f
commit
84ec66c7ce
@ -2017,10 +2017,8 @@ unsigned short GMenu2X::getBatteryLevel() {
|
||||
#else
|
||||
if (!batteryHandle) return 0;
|
||||
int battval = 0;
|
||||
char battvalcstr[5];
|
||||
fscanf(batteryHandle, "%s", &battvalcstr[0]);
|
||||
fscanf(batteryHandle, "%d", &battval);
|
||||
rewind(batteryHandle);
|
||||
battval = atoi(battvalcstr);
|
||||
if (battval>90) return 5;
|
||||
if (battval>70) return 4;
|
||||
if (battval>50) return 3;
|
||||
@ -2029,10 +2027,8 @@ unsigned short GMenu2X::getBatteryLevel() {
|
||||
|
||||
if (!usbHandle) return 0;
|
||||
int usbval = 0;
|
||||
char usbvalcstr[5];
|
||||
fscanf(usbHandle, "%s", &usbvalcstr[0]);
|
||||
fscanf(usbHandle, "%d", &usbval);
|
||||
rewind(usbHandle);
|
||||
usbval = atoi(usbvalcstr);
|
||||
if (usbval==1) return 6;
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user