Parse a substring out of string, allocate memory accordingly I have written the following code in order to:


Find begin and end of FTP user and password from a given URL (ftp://[user[:password]@]host[:port]/url-path)
Allocate memory to hold this string
Copy the sub-string into the allocated memory


Here is the code for your review:

static char * swd_parseUsrPass(void)
{
    char *usr_pass = NULL;
    char *url_str = NULL;
    char *beginIndx = NULL;
    char *endIndx = NULL;
    int str_len = 0;

    url_str = getURLaddr();

    /* Find begin and end indexs */
    beginIndx = url_str + strlen(FTP_PREFIX);
    endIndx = strchr(beginIndx, '@');

    if ((endIndx == NULL) || endIndx &lt;= beginIndx) {
        printf("Could not locate user and password in URL\n");
        return NULL;
    }

    str_len = endIndx - beginIndx;

    /* Allocate maximum possible string */
    usr_pass = malloc((sizeof(char) * str_len) + 1);
    if (usr_pass == NULL) {
        printf("Failed to allocated memory!\n");
        return NULL;
    }

    /* Copy user and password to new string */
    strncpy(usr_pass, beginIndx, str_len);
    *(endIndx + 1) = '\0';

    return usr_pass;
}
A 0-ary function (swd_parseUsrPass) calling another 0-ary function (swd_getURLaddr) hints that there are global variables lurking around. Using globals is not recommended; if they are unavoidable, at least limit their visibility. Consider char swd_parseUsrPass(char * url_addr), and let the caller provide the argument.
sizeof(char) is guaranteed to be 1.
*(endIndx + 1) = '\0' modifies the source string, while usr_pass remains not terminated. I presume you meant

usr_pass[str_len] = '\0';