본문으로 바로가기

mman (mmap for mingw)

category Devlogs 2024. 3. 6. 10:24

posix의 메모리 매핑 api인 mmap 을 windows api 를 이용하여 그대로 구현한 mman 라이브러리..

mman-win32-master.zip
0.02MB

    mode_t mode = S_IRUSR | S_IWUSR;
    int o = open(map_file_name, O_TRUNC | O_BINARY | O_RDWR | O_CREAT, mode);

    void* map = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_PRIVATE, o, 0);
    if (map == MAP_FAILED)
    {
        printf("mmap returned unexpected error: %d\n", errno);
        return -1;
    }

    *((unsigned char*)map) = 1;
    
    int result = munmap(map, 1024);
    
    if (result != 0)
        printf("munmap returned unexpected error: %d\n", errno);
    
    close(o);
    
    /*TODO: get file info and content and compare it with the sources conditions */
    unlink(map_file_name);

 


Korea Tcl/Tk Community
블로그 이미지 ihmin 님의 블로그
VISITOR 오늘 / 전체