aboutsummaryrefslogblamecommitdiffstats
path: root/cmd/cmd_uptime.c
blob: c4dfda79a4ab00cdc0632cbebd5baa32f03c2ca0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                       


                                                

                            
                                     

                         


                                 
                           


                     
                  






                                           

                                                                                      
                                                                                    

                                 


                   
#include "cmd_uptime.h"

#define PROCFS_PATH "/proc"
#define PROCFS_UPTIME_PATH PROCFS_PATH "/uptime"

void *cmd_uptime(void *data)
{
	//char *param = (char *)data;
	char *ret = NULL;

	const int buf_size = 128;
	char buf[buf_size+1];

	printf("UPTIME\n");

	FILE *f=NULL;
	double d1,d2;
	int    i1;

	f = fopen(PROCFS_UPTIME_PATH,"r");
	fscanf(f,"%lf %lf", &d1, &d2);
	fclose(f);

	printf("Readed %lf %lf\n", d1, d2);
	i1 = d1;

	printf("Days %d Hours %d Minutes %d\n",i1/(3600*24),i1/(3600)%24, (i1/60)%60);
	snprintf(buf, buf_size,"%dd %dh %dm",i1/(3600*24),i1/(3600)%24, (i1/60)%60);

	ret = alloc_new_str(buf);

	return ret;
}