The example strdup implementation:
  char *strdup(const char *str) { 
    size_t len = strlen(str);
    char *retval = malloc(len);
    if (!retval) {
      return NULL; 
    }
    strcpy(retval, str);
    return retval;
  }
Also, assuming a NULL pointer is bitwise equal to 0 is not portable.
 replies(2):