#include #define MAX_ERRNO 4095 #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) static inline long IS_ERR(const void *ptr) { return IS_ERR_VALUE((unsigned long)ptr); } static inline long PTR_ERR(const void *ptr) { return (long) ptr; } int main(int argc, const char *argv[]) { void *ptr = (void *)-1; printf("ptr = %p, -PTR_ERR(ptr) = %ld\n\n", ptr, -PTR_ERR(ptr)); if(IS_ERR(ptr)) { if (-PTR_ERR(ptr) < 0) printf("That's what the codes want.\n"); else printf("Bug happens!\n"); } return 0; }