3 ms·
Leaving this here as comments on that blog seem broken. TL;DR: access(2) is a bit more lightweight than write(2) for this purpose. Consider the following (from
by oomo 6y ago
Leaving this here as comments on that blog seem broken. TL;DR: access(2) is a bit more lightweight than write(2) for this purpose.
Consider the following (from memory, untested):
word_t peek(word_t addr, int success) {
word_t ret;
errno = 0;
access(addr, F_OK);
if (success)
success = (errno != EFAULT);
if (errno != EFAULT)
ret = *addr;
return ret;
}
I first learnt about this trick in http://www.gcu-squad.org/2005/08/non-ce-n-est-pas-sale%21/ http://www.gcu-squad.org/2005/08/non-ce-n-est-pas-sale%21/