@ -44,8 +44,9 @@ smprintf(const char *fmt, ...)
char * ret = NULL ;
char * ret = NULL ;
va_start ( fmtargs , fmt ) ;
va_start ( fmtargs , fmt ) ;
if ( vasprintf ( & ret , fmt , fmtargs ) < 0 )
if ( vasprintf ( & ret , fmt , fmtargs ) < 0 ) {
return NULL ;
return NULL ;
}
va_end ( fmtargs ) ;
va_end ( fmtargs ) ;
return ret ;
return ret ;
@ -74,7 +75,7 @@ battery_perc(const char *battery)
/* open battery now file */
/* open battery now file */
if ( ! ( fp = fopen ( batterynowfile , " r " ) ) ) {
if ( ! ( fp = fopen ( batterynowfile , " r " ) ) ) {
fprintf ( stderr , " Error opening battery file.%s " , batterynowfile ) ;
fprintf ( stderr , " Error opening battery file.%s " , batterynowfile ) ;
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
@ -160,7 +161,7 @@ datetime(const char *timeformat)
/* get time in format */
/* get time in format */
time ( & tm ) ;
time ( & tm ) ;
setlocale ( LC_TIME , " " ) ;
setlocale ( LC_TIME , " " ) ;
if ( ! strftime ( buf , bufsize , timeformat , localtime ( & tm ) ) ) {
if ( ! strftime ( buf , bufsize , timeformat , localtime ( & tm ) ) ) {
setlocale ( LC_TIME , " C " ) ;
setlocale ( LC_TIME , " C " ) ;
free ( buf ) ;
free ( buf ) ;
fprintf ( stderr , " Strftime failed. \n " ) ;
fprintf ( stderr , " Strftime failed. \n " ) ;
@ -313,24 +314,21 @@ ip(const char *interface)
char host [ NI_MAXHOST ] ;
char host [ NI_MAXHOST ] ;
/* check if getting ip address works */
/* check if getting ip address works */
if ( getifaddrs ( & ifaddr ) = = - 1 )
if ( getifaddrs ( & ifaddr ) = = - 1 ) {
{
fprintf ( stderr , " Error getting IP address. " ) ;
fprintf ( stderr , " Error getting IP address. " ) ;
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
/* get the ip address */
/* get the ip address */
for ( ifa = ifaddr ; ifa ! = NULL ; ifa = ifa - > ifa_next )
for ( ifa = ifaddr ; ifa ! = NULL ; ifa = ifa - > ifa_next ) {
{
if ( ifa - > ifa_addr = = NULL ) {
if ( ifa - > ifa_addr = = NULL )
continue ;
continue ;
}
s = getnameinfo ( ifa - > ifa_addr , sizeof ( struct sockaddr_in ) , host , NI_MAXHOST , NULL , 0 , NI_NUMERICHOST ) ;
s = getnameinfo ( ifa - > ifa_addr , sizeof ( struct sockaddr_in ) , host , NI_MAXHOST , NULL , 0 , NI_NUMERICHOST ) ;
if ( ( strcmp ( ifa - > ifa_name , interface ) = = 0 ) & & ( ifa - > ifa_addr - > sa_family = = AF_INET ) )
if ( ( strcmp ( ifa - > ifa_name , interface ) = = 0 ) & & ( ifa - > ifa_addr - > sa_family = = AF_INET ) ) {
{
if ( s ! = 0 ) {
if ( s ! = 0 )
{
fprintf ( stderr , " Error getting IP address. " ) ;
fprintf ( stderr , " Error getting IP address. " ) ;
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
@ -465,13 +463,13 @@ run_command(const char* command)
}
}
/* get command output text, save it to buffer */
/* get command output text, save it to buffer */
fgets ( buffer , sizeof ( buffer ) - 1 , fp ) ;
fgets ( buffer , sizeof ( buffer ) - 1 , fp ) ;
/* close it again */
/* close it again */
pclose ( fp ) ;
pclose ( fp ) ;
/* add nullchar at the end */
/* add nullchar at the end */
for ( int i = 0 ; i ! = sizeof ( buffer ) ; i + + ) {
for ( int i = 0 ; i ! = sizeof ( buffer ) ; i + + ) {
if ( buffer [ i ] = = ' \0 ' ) {
if ( buffer [ i ] = = ' \0 ' ) {
good = 1 ;
good = 1 ;
break ;
break ;
@ -516,14 +514,13 @@ username(const char *null)
register uid_t uid ;
register uid_t uid ;
/* get the values */
/* get the values */
uid = geteuid ( ) ;
uid = geteuid ( ) ;
pw = getpwuid ( uid ) ;
pw = getpwuid ( uid ) ;
/* if it worked, return */
/* if it worked, return */
if ( pw ) {
if ( pw ) {
return smprintf ( " %s " , pw - > pw_name ) ;
return smprintf ( " %s " , pw - > pw_name ) ;
}
} else {
else {
fprintf ( stderr , " Could not get username. \n " ) ;
fprintf ( stderr , " Could not get username. \n " ) ;
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
@ -538,13 +535,12 @@ uid(const char *null)
register uid_t uid ;
register uid_t uid ;
/* get the values */
/* get the values */
uid = geteuid ( ) ;
uid = geteuid ( ) ;
/* if it worked, return */
/* if it worked, return */
if ( uid ) {
if ( uid ) {
return smprintf ( " %d " , uid ) ;
return smprintf ( " %d " , uid ) ;
}
} else {
else {
fprintf ( stderr , " Could not get uid. \n " ) ;
fprintf ( stderr , " Could not get uid. \n " ) ;
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
@ -601,8 +597,7 @@ vol_perc(const char *soundcard)
/* return the string (mute) */
/* return the string (mute) */
if ( ! mute ) {
if ( ! mute ) {
return smprintf ( " mute " ) ;
return smprintf ( " mute " ) ;
}
} else {
else {
return smprintf ( " %d%% " , ( vol * 100 ) / max ) ;
return smprintf ( " %d%% " , ( vol * 100 ) / max ) ;
}
}
}
}
@ -639,7 +634,7 @@ wifi_perc(const char *wificard)
fclose ( fp ) ;
fclose ( fp ) ;
/* check if interface down */
/* check if interface down */
if ( strcmp ( status , " up \n " ) ! = 0 ) {
if ( strcmp ( status , " up \n " ) ! = 0 ) {
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
}
@ -696,8 +691,7 @@ wifi_essid(const char *wificard)
/* return the essid */
/* return the essid */
if ( strcmp ( ( char * ) wreq . u . essid . pointer , " " ) = = 0 ) {
if ( strcmp ( ( char * ) wreq . u . essid . pointer , " " ) = = 0 ) {
return smprintf ( " n/a " ) ;
return smprintf ( " n/a " ) ;
}
} else {
else {
return smprintf ( " %s " , ( char * ) wreq . u . essid . pointer ) ;
return smprintf ( " %s " , ( char * ) wreq . u . essid . pointer ) ;
}
}
}
}