Subversion Repositories HelenOS

Rev

Rev 3461 | Rev 3481 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3461 Rev 3480
Line 73... Line 73...
73
/*
73
/*
74
 * Take a previously allocated string (s1), re-size it to accept s2 and copy
74
 * Take a previously allocated string (s1), re-size it to accept s2 and copy
75
 * the contents of s2 into s1.
75
 * the contents of s2 into s1.
76
 * Return -1 on failure, or the length of the copied string on success.
76
 * Return -1 on failure, or the length of the copied string on success.
77
 */
77
 */
78
int cli_redup(char **s1, const char *s2)
78
size_t cli_redup(char **s1, const char *s2)
79
{
79
{
80
    size_t len = strlen(s2) + 1;
80
    size_t len = strlen(s2) + 1;
81
 
81
 
82
    if (! len)
82
    if (! len)
83
        return -1;
83
        return -1;
Line 90... Line 90...
90
    }
90
    }
91
 
91
 
92
    memset(*s1, 0, sizeof(*s1));
92
    memset(*s1, 0, sizeof(*s1));
93
    memcpy(*s1, s2, len);
93
    memcpy(*s1, s2, len);
94
    cli_errno = CL_EOK;
94
    cli_errno = CL_EOK;
95
    return (int) len;
95
    return len;
96
}
96
}
97
 
97
 
98
/* An asprintf() for formatting paths, similar to asprintf() but ensures
98
/* An asprintf() for formatting paths, similar to asprintf() but ensures
99
 * the returned allocated string is <= PATH_MAX. On failure, an attempt
99
 * the returned allocated string is <= PATH_MAX. On failure, an attempt
100
 * is made to return the original string (if not null) unmodified.
100
 * is made to return the original string (if not null) unmodified.