How can I check whether a memory address is writable or not at runtime?
For example, I want to implement is_writable_address in following code. Is it possible?
#include <stdio.h>
int is_writable_address(void *p) {
// TODO
}
void func(char *s) {
if (is_writable_address(s)) {
*s = 'x';
}
}
int main() {
char *s1 = "foo";
char s2[] = "bar";
func(s1);
func(s2);
printf("%s, %s\n", s1, s2);
return 0;
}