aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-22 04:35:12 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2007-06-22 04:35:12 +0000
commited2b193e6c6d0cce882796969369e305075103e0 (patch)
tree45f02eef0ac120e193459b71f73a7b62b7db8784 /apps
parentde3fbdf9699a307db497cd68d3d9d044936d7b4f (diff)
Issue 9990 - New API ast_mkdir, which creates parent directories as necessary (and is faster than an outcall to mkdir -p)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@71040 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_dial.c8
-rw-r--r--apps/app_dictate.c2
-rw-r--r--apps/app_minivm.c27
-rw-r--r--apps/app_sms.c12
-rw-r--r--apps/app_test.c4
-rw-r--r--apps/app_voicemail.c30
6 files changed, 24 insertions, 59 deletions
diff --git a/apps/app_dial.c b/apps/app_dial.c
index 7ecf8eef1..035604e67 100644
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -1146,13 +1146,13 @@ static int setup_privacy_args(struct privacy_args *pa,
/* make sure the priv-callerintros dir actually exists */
snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
- if (mkdir(pa->privintro, 0755) && errno != EEXIST) {
- ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(errno));
+ if ((res = ast_mkdir(pa->privintro, 0755))) {
+ ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
return -1;
}
- snprintf(pa->privintro,sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
- if (ast_fileexists(pa->privintro,NULL,NULL ) > 0 && strncmp(pa->privcid,"NOCALLERID",10) != 0) {
+ snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
+ if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
/* the DELUX version of this code would allow this caller the
option to hear and retape their previously recorded intro.
*/
diff --git a/apps/app_dictate.c b/apps/app_dictate.c
index c501b3f78..61252433d 100644
--- a/apps/app_dictate.c
+++ b/apps/app_dictate.c
@@ -139,7 +139,7 @@ static int dictate_exec(struct ast_channel *chan, void *data)
ast_copy_string(filein, filename, sizeof(filein));
filename = "";
}
- mkdir(base, 0755);
+ ast_mkdir(base, 0755);
len = strlen(base) + strlen(filein) + 2;
if (!path || len > maxlen) {
path = alloca(len);
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 682520b1c..73ef61b28 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -1159,28 +1159,11 @@ static int check_dirpath(char *dest, int len, char *domain, char *username, char
*/
static int create_dirpath(char *dest, int len, char *domain, char *username, char *folder)
{
- mode_t mode = VOICEMAIL_DIR_MODE;
-
- if(!ast_strlen_zero(domain)) {
- make_dir(dest, len, domain, "", "");
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
- }
- if(!ast_strlen_zero(username)) {
- make_dir(dest, len, domain, username, "");
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
- }
- if(!ast_strlen_zero(folder)) {
- make_dir(dest, len, domain, username, folder);
- if(mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
+ int res;
+ make_dir(dest, len, domain, username, folder);
+ if ((res = ast_mkdir(dest, 0777))) {
+ ast_log(LOG_WARNING, "ast_mkdir '%s' failed: %s\n", dest, strerror(res));
+ return -1;
}
ast_debug(2, "Creating directory for %s@%s folder %s : %s\n", username, domain, folder, dest);
return 0;
diff --git a/apps/app_sms.c b/apps/app_sms.c
index f1022bb26..d29ab6985 100644
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -916,10 +916,8 @@ static void sms_writefile(sms_t * h)
char buf[30];
FILE *o;
- ast_copy_string(fn, spool_dir, sizeof (fn));
- mkdir(fn, 0777); /* ensure it exists */
- snprintf(fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
- mkdir(fn, 0777); /* ensure it exists */
+ snprintf(fn, sizeof(fn), "%s/%s", spool_dir, h->smsc ? h->rx ? "morx" : "mttx" : h->rx ? "mtrx" : "motx");
+ ast_mkdir(fn, 0777); /* ensure it exists */
ast_copy_string(fn2, fn, sizeof (fn2));
snprintf(fn2 + strlen (fn2), sizeof (fn2) - strlen (fn2), "/%s.%s-%d", h->queue, isodate(h->scts, buf, sizeof(buf)), seq++);
snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/.%s", fn2 + strlen (fn) + 1);
@@ -1339,11 +1337,9 @@ static void sms_nextoutgoing (sms_t * h)
char more = 0;
*h->da = *h->oa = '\0'; /* clear destinations */
- ast_copy_string (fn, spool_dir, sizeof (fn));
- mkdir(fn, 0777); /* ensure it exists */
h->rx = 0; /* outgoing message */
- snprintf (fn + strlen (fn), sizeof (fn) - strlen (fn), "/%s", h->smsc ? "mttx" : "motx");
- mkdir (fn, 0777); /* ensure it exists */
+ snprintf(fn, sizeof(fn), "%s/%s", spool_dir, h->smsc ? "mttx" : "motx");
+ ast_mkdir(fn, 0777); /* ensure it exists */
d = opendir (fn);
if (d) {
struct dirent *f = readdirqueue (d, h->queue);
diff --git a/apps/app_test.c b/apps/app_test.c
index a41403a18..8bf7b9e8c 100644
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -177,7 +177,7 @@ static int testclient_exec(struct ast_channel *chan, void *data)
if ((res >=0) && (!ast_strlen_zero(testid))) {
/* Make the directory to hold the test results in case it's not there */
snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
- mkdir(fn, 0777);
+ ast_mkdir(fn, 0777);
snprintf(fn, sizeof(fn), "%s/testresults/%s-client.txt", ast_config_AST_LOG_DIR, testid);
if ((f = fopen(fn, "w+"))) {
setlinebuf(f);
@@ -338,7 +338,7 @@ static int testserver_exec(struct ast_channel *chan, void *data)
/* Got a Test ID! Whoo hoo! */
/* Make the directory to hold the test results in case it's not there */
snprintf(fn, sizeof(fn), "%s/testresults", ast_config_AST_LOG_DIR);
- mkdir(fn, 0777);
+ ast_mkdir(fn, 0777);
snprintf(fn, sizeof(fn), "%s/testresults/%s-server.txt", ast_config_AST_LOG_DIR, testid);
if ((f = fopen(fn, "w+"))) {
setlinebuf(f);
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index b68337c93..e5572dd58 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -939,8 +939,9 @@ static int make_dir(char *dest, int len, const char *context, const char *ext, c
#ifdef IMAP_STORAGE
static int make_gsm_file(char *dest, char *imapuser, char *dir, int num)
{
- if (mkdir(dir, 01777) && (errno != EEXIST)) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dir, strerror(errno));
+ int res;
+ if ((res = ast_mkdir(dir, 01777))) {
+ ast_log(LOG_WARNING, "ast_mkdir '%s' failed: %s\n", dir, strerror(res));
return sprintf(dest, "%s/msg%04d", dir, num);
}
/* return sprintf(dest, "%s/s/msg%04d", dir, imapuser, num); */
@@ -983,27 +984,12 @@ static int make_file(char *dest, int len, char *dir, int num)
static int create_dirpath(char *dest, int len, const char *context, const char *ext, const char *folder)
{
mode_t mode = VOICEMAIL_DIR_MODE;
+ int res;
- if (!ast_strlen_zero(context)) {
- make_dir(dest, len, context, "", "");
- if (mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
- }
- if (!ast_strlen_zero(ext)) {
- make_dir(dest, len, context, ext, "");
- if (mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
- }
- if (!ast_strlen_zero(folder)) {
- make_dir(dest, len, context, ext, folder);
- if (mkdir(dest, mode) && errno != EEXIST) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", dest, strerror(errno));
- return -1;
- }
+ make_dir(dest, len, context, ext, folder);
+ if ((res = ast_mkdir(dest, mode))) {
+ ast_log(LOG_WARNING, "ast_mkdir '%s' failed: %s\n", dest, strerror(res));
+ return -1;
}
return 0;
}