7 typedef struct fakemmapwritable
{
12 struct fakemmapwritable
*next
;
15 static fakemmapwritable
*writablelist
= NULL
;
17 void *gitfakemmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
)
22 die("Invalid usage of gitfakemmap.");
24 if(lseek(fd
, offset
, SEEK_SET
)<0) {
29 start
= xmalloc(length
);
36 int count
= read(fd
, start
+n
, length
-n
);
39 memset(start
+n
, 0, length
-n
);
52 if(prot
& PROT_WRITE
) {
53 fakemmapwritable
*next
= xmalloc(sizeof(fakemmapwritable
));
55 next
->length
= length
;
57 next
->offset
= offset
;
58 next
->next
= writablelist
;
65 int gitfakemunmap(void *start
, size_t length
)
67 fakemmapwritable
*writable
= writablelist
, *before
= NULL
;
69 while(writable
&& (writable
->start
> start
+ length
70 || writable
->start
+ writable
->length
< start
)) {
72 writable
= writable
->next
;
76 /* need to write back the contents */
79 if(writable
->start
!= start
|| writable
->length
!= length
)
80 die("fakemmap does not support partial write back.");
82 if(lseek(writable
->fd
, writable
->offset
, SEEK_SET
) < 0) {
89 int count
= write(writable
->fd
, start
+ n
, length
- n
);
102 before
->next
= writable
->next
;
104 writablelist
= writable
->next
;