/* Change Logs: Date Author Notes  Bernard The first version.  */
void* mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
/* Change Logs: Date Author Notes  Bernard The first version.  */
void* mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
{
    uint8_t *mem;
    if (addr)
    {
        mem = addr;
    }
    else mem = (uint8_t *)malloc(length);
    if (mem)
    {
        off_t cur;
        size_t read_bytes;
        cur = lseek(fd, 0, SEEK_SET);
        lseek(fd, offset, SEEK_SET);
        read_bytes = read(fd, mem, length);
        if (read_bytes != length)
        {
            if (addr == RT_NULL)
            {
                free(mem);
                mem = RT_NULL;
            }
        }
        lseek(fd, cur, SEEK_SET);
        return mem;
    }
    errno = ENOMEM;
    return MAP_FAILED;
}