res_stir_shaken: refactor utility function

Refactors temp file utility function into file.c.

ASTERISK-29809 #close

Change-Id: Ife478708c8f2b127239cb73c1755ef18c0bf431b
This commit is contained in:
Naveen Albert
2021-12-16 19:41:56 +00:00
committed by Kevin Harwell
parent 39820e3561
commit 1633410161
3 changed files with 41 additions and 34 deletions

View File

@@ -199,6 +199,26 @@ FILE *ast_file_mkftemp(char *template, mode_t mode)
return p;
}
int ast_file_fdtemp(const char *path, char **filename, const char *template_name)
{
int fd;
if (ast_asprintf(filename, "%s/%s", path, template_name) < 0) {
ast_log(LOG_ERROR, "Failed to set up temporary file path\n");
return -1;
}
ast_mkdir(path, 0644);
if ((fd = mkstemp(*filename)) < 0) {
ast_log(LOG_NOTICE, "Failed to create temporary file\n");
ast_free(*filename);
return -1;
}
return fd;
}
int ast_stopstream(struct ast_channel *tmp)
{
ast_channel_lock(tmp);