gcc 4.4 build fix
[qbat.git] / common.cpp
blobad3cdd8105b7195ffda244730af2427e4e477eaf
1 //
2 // C++ Implementation: common
3 //
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
5 //
6 // Copyright: See COPYING file that comes with this distribution
7 //
8 #include <cstdlib>
9 #include <cstdio>
10 #include "common.h"
12 namespace qbat {
13 using namespace std;
15 bool readStringFromFile(char * buffer, const char * fileName) {
16 FILE *f = NULL;
17 f = fopen(fileName, "r");
18 if (f) {
19 fgets(buffer, BUF_SIZE, f);
20 fclose(f);
22 bool fill = false;
23 for (int i = 0; i < BUF_SIZE; i++) {
24 if (buffer[i] == '\n')
25 fill = true;
26 if (fill)
27 buffer[i] = '\0';
30 return true;
32 else
33 return false;
36 int readIntSysFile(const char * fileName) {
37 char buffer[BUF_SIZE];
38 readStringFromFile(buffer, fileName);
39 return atoi(buffer);
42 int toStatusInt(const char * status) {
43 if (strcmp(status, "Discharging") == 0)
44 return UI_BATTERY_DISCHARGING;
45 else if (strcmp(status, "Charging") == 0)
46 return UI_BATTERY_CHARGING;
47 else if (strcmp(status, "Full") == 0)
48 return UI_BATTERY_FULL;
49 else
50 return 0;