Align loader to 32-bit boundary
[fw/stlink] / src / mmap.c
1 #include <string.h>
2 #include <sys/types.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include "mmap.h"
7
8 void *mmap (void *addr, size_t len, int prot, int flags, int fd, long long  offset) {
9
10     void *buf;
11     ssize_t count;
12
13     if ( addr || fd == -1 || (prot & PROT_WRITE)) return MAP_FAILED;
14
15     buf = malloc(len);
16     if ( NULL == buf ) return MAP_FAILED;
17
18     if (lseek(fd,offset,SEEK_SET) != offset) return MAP_FAILED;
19
20     count = read(fd, buf, len);
21
22     if (count != len) {
23         free (buf);
24         return MAP_FAILED;
25     }
26
27     return buf;
28 }
29
30 int munmap (void *addr, size_t len) {
31     free (addr);
32     return 0;
33 }