#include <iostream>
#include <stdio.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
using namespace std;
class now_Time
{
private:
time_t my_time;
char *now_time;
public:
now_Time()
{
my_time=time(NULL);
now_time=asctime(localtime(&my_time));
}
char *give_Time()
{
return now_time;
}
};
class uptime_Time
{
private:
FILE *uptime_file;
char *path;
double real_time;
double free_time;
public:
uptime_Time()
{
path="/proc/uptime";
uptime_file=fopen(path,"r");
fscanf(uptime_file,"%1f %1f\n",&real_time,&free_time);
}
int give_real_Time()
{
return (int) real_time;
}
int give_free_Time()
{
return (int) free_time;
}
};
class new_file_with_Infos
{
private:
char *name_file;
size_t size_class_time;
size_t size_free_time;
size_t size_real_time;
int file;
mode_t mode_value;
public:
new_file_with_Infos(char *name)
{
name_file=name;
mode_value=S_IRUSR | S_IROTH | S_IWGRP | S_IRGRP | S_IWUSR;
file=open(name_file, O_WRONLY | O_EXCL | O_CREAT, mode_value);
now_Time nT;
uptime_Time uT;
size_class_time=strlen(nT.give_Time());
char *temp_free_time;
char *temp_real_time;
snprintf(temp_free_time,sizeof(temp_free_time),"%d",uT.give_free_Time());
size_free_time=strlen(temp_free_time);
snprintf(temp_real_time,sizeof(temp_real_time),"%d",uT.give_real_Time());
size_real_time=strlen(temp_real_time);
write(file,nT.give_Time(),size_class_time);
write(file,temp_free_time,size_free_time);
write(file,temp_real_time,size_real_time);
close(file);
}
};
Brak komentarzy:
Prześlij komentarz