Sto' tentando di rifare la strcat con il controllo sulla memoria (se ho abbastanza memoria per copiare str2 dopo str1) ma ho qualche problema e non riesco a capire dove...

Potete Aiutarmi...

size_t e' un unsigned int....

codice:
char *cat(char *str1, const char *str2) {
   size_t mem_str1 = sizeof(str1);
   size_t end_str1 = strlen(str1);
   size_t mem_nec = (end_str1 + strlen(str2))*sizeof(char);

   /* Not Enough Memory */
   if (mem_nec > mem_str1) {
      return (NULL);		
   }

   /* Concat Strings */
   while ((*(str1 + end_str1) = *str2) != '\0') {
      str1++;
      str2++;
   }
   *(str1+1) = '\0';
   
   return ((char *)str1);
};
Altra cosa... se faccio stampare il sizeof(str1) nella funzione ho un byte in piu' rispetto alla stringa che definisco 'nel main'...
Come mai ???