this is my realloc version, is it good ? any suggestion are welcomed I am trying to recode some c functions myself.
This is an my implementation of realloc function, any updates or suggestion about how to improve it are welcomed.
void    *ft_realloc(void *old_ptr, size_t old_size, size_t size) {
    void *new_ptr;
    
    if (size == 0 &amp;&amp; old_ptr != NULL)
    {
        free (old_ptr);
        return (NULL);
    }
    else if (old_ptr == NULL)
    {
        if (!(old_ptr = malloc (size)))
            return (NULL);
        ft_memset(old_ptr, 0, size);
        return (old_ptr);
    }
    else if (size &gt;= old_size) {
        if (!(new_ptr = malloc (size)))
            return (NULL);
        ft_memset(new_ptr, 0, size);
        ft_strncpy (new_ptr, old_ptr, old_size);
        free (old_ptr);
        return (new_ptr);
    }
    else if (size &lt; old_size)
    {
        if (!(new_ptr = malloc(size)))
            return (NULL);
        ft_memset(new_ptr, 0, size);
        ft_strncpy (new_ptr, old_ptr, size);
        free (old_ptr);
        return (new_ptr);
    }
    return (NULL);
}

ft_memset and ft_strncpy are just my implementation of memset and strncpy they behave the same way!
#include &lt;stddef.h&gt;
#include &lt;stdlib.h&gt;

void    *ft_realloc(void *old_ptr, size_t old_size, size_t size) {
    if (size == 0 &amp;&amp; old_ptr != NULL)
    {
        free (old_ptr);
    }
    else if (old_ptr == NULL)
    {
        if (old_ptr = malloc(size))
        {
            ft_memset(old_ptr, 0, size);
            return (old_ptr);
        }
    }
    else
    {
        void *new_ptr;
        if (new_ptr = malloc(size))
        {
            ft_memset(new_ptr, 0, size);
            
            if (size &gt;= old_size)
                ft_strncpy (new_ptr, old_ptr, old_size);
            else
                ft_strncpy (new_ptr, old_ptr, size);
            
            free (old_ptr);
            return (new_ptr);
        }
    }
    return (NULL);
}

My insightful observation: OP's code has redundancies.
My answer: I removed some redundancies, which makes the code possible faster and easier to maintain.