@@ -44,14 +44,17 @@ static const char *sys_class_power_supply_path = "/sys/class/power_supply";
4444static int
4545open_power_file (const char * base , const char * node , const char * key )
4646{
47- const size_t pathlen = strlen (base ) + strlen (node ) + strlen (key ) + 3 ;
48- char * path = (char * ) alloca (pathlen );
47+ int fd ;
48+ const size_t pathlen = SDL_strlen (base ) + SDL_strlen (node ) + SDL_strlen (key ) + 3 ;
49+ char * path = SDL_stack_alloc (char , pathlen );
4950 if (path == NULL ) {
5051 return -1 ; /* oh well. */
5152 }
5253
5354 snprintf (path , pathlen , "%s/%s/%s" , base , node , key );
54- return open (path , O_RDONLY | O_CLOEXEC );
55+ fd = open (path , O_RDONLY | O_CLOEXEC );
56+ SDL_stack_free (path );
57+ return fd ;
5558}
5659
5760
@@ -146,20 +149,20 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
146149
147150 ptr = & state [0 ];
148151 while (make_proc_acpi_key_val (& ptr , & key , & val )) {
149- if (strcmp (key , "present" ) == 0 ) {
150- if (strcmp (val , "yes" ) == 0 ) {
152+ if (SDL_strcmp (key , "present" ) == 0 ) {
153+ if (SDL_strcmp (val , "yes" ) == 0 ) {
151154 * have_battery = SDL_TRUE ;
152155 }
153- } else if (strcmp (key , "charging state" ) == 0 ) {
156+ } else if (SDL_strcmp (key , "charging state" ) == 0 ) {
154157 /* !!! FIXME: what exactly _does_ charging/discharging mean? */
155- if (strcmp (val , "charging/discharging" ) == 0 ) {
158+ if (SDL_strcmp (val , "charging/discharging" ) == 0 ) {
156159 charge = SDL_TRUE ;
157- } else if (strcmp (val , "charging" ) == 0 ) {
160+ } else if (SDL_strcmp (val , "charging" ) == 0 ) {
158161 charge = SDL_TRUE ;
159162 }
160- } else if (strcmp (key , "remaining capacity" ) == 0 ) {
163+ } else if (SDL_strcmp (key , "remaining capacity" ) == 0 ) {
161164 char * endptr = NULL ;
162- const int cvt = (int ) strtol (val , & endptr , 10 );
165+ const int cvt = (int ) SDL_strtol (val , & endptr , 10 );
163166 if (* endptr == ' ' ) {
164167 remaining = cvt ;
165168 }
@@ -168,9 +171,9 @@ check_proc_acpi_battery(const char * node, SDL_bool * have_battery,
168171
169172 ptr = & info [0 ];
170173 while (make_proc_acpi_key_val (& ptr , & key , & val )) {
171- if (strcmp (key , "design capacity" ) == 0 ) {
174+ if (SDL_strcmp (key , "design capacity" ) == 0 ) {
172175 char * endptr = NULL ;
173- const int cvt = (int ) strtol (val , & endptr , 10 );
176+ const int cvt = (int ) SDL_strtol (val , & endptr , 10 );
174177 if (* endptr == ' ' ) {
175178 maximum = cvt ;
176179 }
@@ -225,8 +228,8 @@ check_proc_acpi_ac_adapter(const char * node, SDL_bool * have_ac)
225228
226229 ptr = & state [0 ];
227230 while (make_proc_acpi_key_val (& ptr , & key , & val )) {
228- if (strcmp (key , "state" ) == 0 ) {
229- if (strcmp (val , "on-line" ) == 0 ) {
231+ if (SDL_strcmp (key , "state" ) == 0 ) {
232+ if (SDL_strcmp (val , "on-line" ) == 0 ) {
230233 * have_ac = SDL_TRUE ;
231234 }
232235 }
@@ -315,7 +318,7 @@ static SDL_bool
315318int_string (char * str , int * val )
316319{
317320 char * endptr = NULL ;
318- * val = (int ) strtol (str , & endptr , 0 );
321+ * val = (int ) SDL_strtol (str , & endptr , 0 );
319322 return ((* str != '\0' ) && (* endptr == '\0' ));
320323}
321324
@@ -377,8 +380,8 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
377380 if (!next_string (& ptr , & str )) { /* remaining battery life percent */
378381 return SDL_FALSE ;
379382 }
380- if (str [strlen (str ) - 1 ] == '%' ) {
381- str [strlen (str ) - 1 ] = '\0' ;
383+ if (str [SDL_strlen (str ) - 1 ] == '%' ) {
384+ str [SDL_strlen (str ) - 1 ] = '\0' ;
382385 }
383386 if (!int_string (str , & battery_percent )) {
384387 return SDL_FALSE ;
@@ -392,7 +395,7 @@ SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState * state,
392395
393396 if (!next_string (& ptr , & str )) { /* remaining battery life time units */
394397 return SDL_FALSE ;
395- } else if (strcmp (str , "min" ) == 0 ) {
398+ } else if (SDL_strcmp (str , "min" ) == 0 ) {
396399 battery_time *= 60 ;
397400 }
398401
0 commit comments