Index: apps/app_record.c =================================================================== --- apps/app_record.c (revision 40820) +++ apps/app_record.c (working copy) @@ -183,8 +183,26 @@ /* these are to allow the use of the %d in the config file for a wild card of sort to create a new file with the inputed name scheme */ if (percentflag) { + AST_DECLARE_APP_ARGS(fname, + AST_APP_ARG(piece)[100]; + ); + char *tmp2 = ast_strdupa(filename); + char countstring[15]; + int i; + + AST_NONSTANDARD_APP_ARGS(fname, tmp2, '%'); do { - snprintf(tmp, sizeof(tmp), filename, count); + ast_copy_string(tmp, fname.piece[0], sizeof(tmp)); + for (i = 1; i < fname.argc; i++) { + if (fname.piece[i][0] == 'd') { + snprintf(countstring, sizeof(countstring), "%d", count); + ast_copy_string(tmp + strlen(tmp), countstring, sizeof(tmp) - strlen(tmp)); + } else if (strlen(tmp) + 2 < sizeof(tmp)) { + tmp[strlen(tmp)] = '%'; + tmp[strlen(tmp)] = fname.piece[i][0]; + } + ast_copy_string(tmp + strlen(tmp), &(fname.piece[i][1]), sizeof(tmp) - strlen(tmp)); + } count++; } while ( ast_fileexists(tmp, ext, chan->language) != -1 ); pbx_builtin_setvar_helper(chan, "RECORDED_FILE", tmp);