C
CFAN
I have written a variable parameter function:
APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t *
buffer_len ,... )
{
char *cp, *argp;
apr_size_t saved_lengths[MAX_SAVED_STR_LENGTHS];
apr_size_t total_len;
int nargs = 0;
/* Pass one --- find length of required string */
apr_size_t len = 0;
va_list adummy;
va_start(adummy, buffer_len );
while ((cp = va_arg(adummy, char *)) != NULL) {
apr_size_t cplen = strlen(cp);
if (nargs < MAX_SAVED_STR_LENGTHS) {
saved_lengths[nargs++] = cplen;
}
(apr_status_t) len += cplen;
}
va_end(adummy);
total_len = len ;
/* Allocate the required string */
if ( len > *buffer_len + 1)
return APR_ENOMEM;
cp = buffer;
/* Pass two --- copy the argument strings into the result space */
va_start(adummy, buffer_len );
nargs = 0;
while ((argp = va_arg(adummy, char *)) != NULL) {
if (nargs < MAX_SAVED_STR_LENGTHS) {
len = saved_lengths[nargs++];
}
else {
len = strlen(argp);
}
//Possible copy it to itself
//example: filename=strcat(filename,"_001","_002",NULL);
//maybe need not , VC memcpy do check overlap
memmove(cp, argp, len);
cp += len;
}
va_end(adummy);
*buffer_len = total_len+1;
*cp = '\0';
return APR_SUCCESS;
}
Now I want to add a function like
sas_strcat_with_enter(char *buffer,size_t * buffer_len ,... )
every thing is as same as the sas_strcat,except for this function will
add a "\n" and the end of string.
how can i make such funtions by calling the sas_strcat from within the
sas_strcat_with_enter function
Thanks.
APR_DECLARE_NONSTD(apr_status_t) sas_strcat(char *buffer,size_t *
buffer_len ,... )
{
char *cp, *argp;
apr_size_t saved_lengths[MAX_SAVED_STR_LENGTHS];
apr_size_t total_len;
int nargs = 0;
/* Pass one --- find length of required string */
apr_size_t len = 0;
va_list adummy;
va_start(adummy, buffer_len );
while ((cp = va_arg(adummy, char *)) != NULL) {
apr_size_t cplen = strlen(cp);
if (nargs < MAX_SAVED_STR_LENGTHS) {
saved_lengths[nargs++] = cplen;
}
(apr_status_t) len += cplen;
}
va_end(adummy);
total_len = len ;
/* Allocate the required string */
if ( len > *buffer_len + 1)
return APR_ENOMEM;
cp = buffer;
/* Pass two --- copy the argument strings into the result space */
va_start(adummy, buffer_len );
nargs = 0;
while ((argp = va_arg(adummy, char *)) != NULL) {
if (nargs < MAX_SAVED_STR_LENGTHS) {
len = saved_lengths[nargs++];
}
else {
len = strlen(argp);
}
//Possible copy it to itself
//example: filename=strcat(filename,"_001","_002",NULL);
//maybe need not , VC memcpy do check overlap
memmove(cp, argp, len);
cp += len;
}
va_end(adummy);
*buffer_len = total_len+1;
*cp = '\0';
return APR_SUCCESS;
}
Now I want to add a function like
sas_strcat_with_enter(char *buffer,size_t * buffer_len ,... )
every thing is as same as the sas_strcat,except for this function will
add a "\n" and the end of string.
how can i make such funtions by calling the sas_strcat from within the
sas_strcat_with_enter function
Thanks.