int STRING_copy_n()

in src/strings.c [532:568]


int STRING_copy_n(STRING_HANDLE handle, const char* s2, size_t n)
{
    int result;
    if ((handle == NULL) || (s2 == NULL))
    {
        /* Codes_SRS_STRING_07_019: [STRING_copy_n shall return a nonzero value if STRING_HANDLE or const char* is NULL.] */
        result = MU_FAILURE;
    }
    else
    {
        STRING* s1 = handle;
        size_t s2Length = strlen(s2);
        char* temp;
        if (s2Length > n)
        {
            s2Length = n;
        }

        temp = realloc_flex(s1->s, 1, s2Length, 1);
        if (temp == NULL)
        {
            LogError("Failure in realloc_flex(s1->s=%s, 1, s2Length=%zu, 1);",
                s1->s, s2Length);
            /* Codes_SRS_STRING_07_028: [STRING_copy_n shall return a nonzero value if any error is encountered.] */
            result = MU_FAILURE;
        }
        else
        {
            s1->s = temp;
            (void)memcpy(s1->s, s2, s2Length);
            s1->s[s2Length] = 0;
            result = 0;
        }

    }
    return result;
}