-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymman.h
39 lines (34 loc) · 765 Bytes
/
mymman.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include "mystd.h"
int open_check(char *str, int flags, mode_t mode) {
int fd;
if (mode)
fd = open(str, flags, mode);
else
fd = open(str, flags);
if (fd == -1)
err("open");
return fd;
}
int close_check(int fd) {
if (close(fd) == -1)
err("close");
return 0;
}
char *mmap_check(void *start, size_t length, int prot, int flags,
int fd, off_t offset) {
char *map = mmap(start, length, prot, flags, fd, offset);
if (map == (void*)-1L)
err("mmap");
return map;
}
int *munmap_check(void *start, size_t length) {
if (munmap(start, length) == -1)
err("munmap");
return 0;
}