#include <iostream>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/time.h>
using namespace std;
class example_MMAP
{
private:
#define width 0x100
void *temp_void;
char *file_name;
int f_file;
public:
example_MMAP(char *file)
{
file_name=file;
f_file=open(file_name,O_RDWR);
lseek(f_file,width+1,SEEK_SET);
write(f_file,"",1);
lseek(f_file,0,SEEK_SET);
temp_void=mmap(0,width,PROT_WRITE,MAP_SHARED,f_file,0);
close(f_file);
}
char *read_time()
{
char *text_time;
struct tm *temp_tm;
struct timeval temp_timeval;
gettimeofday(&temp_timeval,NULL);
temp_tm=localtime(&temp_timeval.tv_sec);
strftime(text_time,sizeof(text_time),"%D-%m-%y %H:%M:%S",temp_tm);
return text_time;
}
void m_write()
{
sprintf((char *)temp_void, "%s\n",read_time());
}
~example_MMAP()
{
munmap(temp_void,width);
}
};
int main(int argc, char **argv)
{
example_MMAP e_M("test_file");
e_M.m_write();
return 0;
}
Brak komentarzy:
Prześlij komentarz