10 size_t Purify_fread (void *ptr
, size_t size
, size_t nmemb
, FILE *stream
)
12 if (!Purify_CheckMemoryAccess (ptr
, size
*nmemb
, PURIFY_MemAccess_Write
))
14 if (Purify_Error
== NotOwnMemory
)
16 Purify_Error
= IllPointer
;
17 Purify_PrintError ("fread (addr=%p, size=%ld, num=%ld, file=%p)"
18 , ptr
, size
, nmemb
, stream
);
22 Purify_PrintAccessError ("fread()", ptr
, size
);
26 return fread (ptr
, size
, nmemb
, stream
);
29 size_t Purify_read (int fd
, void *ptr
, size_t size
)
31 if (!Purify_CheckMemoryAccess (ptr
, size
, PURIFY_MemAccess_Write
))
33 if (Purify_Error
== NotOwnMemory
)
35 Purify_Error
= IllPointer
;
36 Purify_PrintError ("read (fd=%d, addr=%p, size=%ld)"
41 Purify_PrintAccessError ("read()", ptr
, size
);
45 return read (fd
, ptr
, size
);
48 char * Purify_fgets (char * ptr
, int size
, FILE * stream
)
50 if (!Purify_CheckMemoryAccess (ptr
, size
, PURIFY_MemAccess_Write
))
52 if (Purify_Error
== NotOwnMemory
)
54 Purify_Error
= IllPointer
;
55 Purify_PrintError ("fgets (ptr=%p, size=%d, stream=%p)"
60 Purify_PrintAccessError ("fgets()", ptr
, size
);
64 return fgets (ptr
, size
, stream
);
67 char * Purify_getcwd (char * buf
, size_t size
)
73 if (!Purify_CheckMemoryAccess (buf
, size
, PURIFY_MemAccess_Write
))
75 if (Purify_Error
== NotOwnMemory
)
77 Purify_Error
= IllPointer
;
78 Purify_PrintError ("getcwd (buf=%p, size=%ld)"
83 Purify_PrintAccessError ("getcwd()", buf
, size
);
87 ret
= getcwd (buf
, size
);
93 ptr
= getcwd (NULL
, size
);
100 ret
= Purify_strdup (ptr
);
109 ret
= Purify_malloc (size
);
116 hash
= Purify_FindMemory (ret
);
117 Purify_SetMemoryFlags (hash
, 0, strlen (ptr
) + 1,
118 PURIFY_MemFlag_Readable
|PURIFY_MemFlag_Writable
128 int Purify_stat (char * path
, struct stat
* st
)
132 if (!Purify_CheckMemoryAccess (path
, 1, PURIFY_MemAccess_Read
))
133 Purify_PrintAccessError ("stat (path, ...)", path
, 1);
135 len
= strlen (path
)+1;
137 if (!Purify_CheckMemoryAccess (path
, len
, PURIFY_MemAccess_Read
))
138 Purify_PrintAccessError ("stat (path, ...)", path
, len
);
140 if (!Purify_CheckMemoryAccess (st
, sizeof (struct stat
), PURIFY_MemAccess_Write
))
141 Purify_PrintAccessError ("stat (..., stat)", st
, sizeof (struct stat
));
143 return stat (path
, st
);
146 int Purify_lstat (char * path
, struct stat
* st
)
150 if (!Purify_CheckMemoryAccess (path
, 1, PURIFY_MemAccess_Read
))
151 Purify_PrintAccessError ("lstat (path, ...)", path
, 1);
153 len
= strlen (path
)+1;
155 if (!Purify_CheckMemoryAccess (path
, len
, PURIFY_MemAccess_Read
))
156 Purify_PrintAccessError ("lstat (path, ...)", path
, len
);
158 if (!Purify_CheckMemoryAccess (st
, sizeof (struct stat
), PURIFY_MemAccess_Write
))
159 Purify_PrintAccessError ("lstat (..., stat)", st
, sizeof (struct stat
));
161 return lstat (path
, st
);
164 int Purify_fstat (int fd
, struct stat
* st
)
166 if (!Purify_CheckMemoryAccess (st
, sizeof (struct stat
), PURIFY_MemAccess_Write
))
167 Purify_PrintAccessError ("fstat (..., stat)", st
, sizeof (struct stat
));
169 return fstat (fd
, st
);
172 struct dirent
* Purify_readdir (DIR * dir
)
174 static struct dirent
* last_de
= NULL
;
184 Purify_RemMemory (last_de
);
186 hash
= Purify_AddMemory (de
, sizeof (struct dirent
),
187 PURIFY_MemFlag_Writable
188 | PURIFY_MemFlag_Readable
189 , PURIFY_MemType_Data
192 hash
->data
= "dirent";