aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-02-09 02:08:04 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2006-02-09 02:08:04 +0000
commitc1fa207982b50394179ed13316b30a333e12c6bb (patch)
tree238d9bc767315255bbb6243d112b595253c2cc6f /file.c
parent1996eb58ac8861e966eab91419ae114d35d59773 (diff)
various code cleanup changes including changing #define'd constants to enums,
comments to doxygen style, memory allocation to use ast_ wrappers, use calloc instead of malloc+memset, and removing duplicated error messages (issue #6435) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@9259 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'file.c')
-rw-r--r--file.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/file.c b/file.c
index 65aa4d74c..766c32abc 100644
--- a/file.c
+++ b/file.c
@@ -124,10 +124,8 @@ int ast_format_register(const char *name, const char *exts, int format,
ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", name);
return -1;
}
- }
- tmp = malloc(sizeof(struct ast_format));
- if (!tmp) {
- ast_log(LOG_WARNING, "Out of memory\n");
+ }
+ if (!(tmp = ast_malloc(sizeof(*tmp)))) {
AST_LIST_UNLOCK(&formats);
return -1;
}
@@ -301,16 +299,14 @@ static char *build_filename(const char *filename, const char *ext)
if (filename[0] == '/') {
fnsize = strlen(filename) + strlen(type) + 2;
- fn = malloc(fnsize);
- if (fn)
+ if ((fn = ast_malloc(fnsize)))
snprintf(fn, fnsize, "%s.%s", filename, type);
} else {
char tmp[AST_CONFIG_MAX_PATH] = "";
snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_VAR_DIR, "sounds");
fnsize = strlen(tmp) + strlen(filename) + strlen(type) + 3;
- fn = malloc(fnsize);
- if (fn)
+ if ((fn = ast_malloc(fnsize)))
snprintf(fn, fnsize, "%s/%s.%s", tmp, filename, type);
}
@@ -333,13 +329,15 @@ static int exts_compare(const char *exts, const char *type)
return 0;
}
-#define ACTION_EXISTS 1
-#define ACTION_DELETE 2
-#define ACTION_RENAME 3
-#define ACTION_OPEN 4
-#define ACTION_COPY 5
+enum file_action {
+ ACTION_EXISTS = 1,
+ ACTION_DELETE,
+ ACTION_RENAME,
+ ACTION_OPEN,
+ ACTION_COPY
+};
-static int ast_filehelper(const char *filename, const char *filename2, const char *fmt, int action)
+static int ast_filehelper(const char *filename, const char *filename2, const char *fmt, const enum file_action action)
{
struct stat st;
struct ast_format *f;
@@ -389,8 +387,7 @@ static int ast_filehelper(const char *filename, const char *filename2, const cha
if (res)
ast_log(LOG_WARNING, "rename(%s,%s) failed: %s\n", fn, nfn, strerror(errno));
free(nfn);
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
+ }
break;
case ACTION_COPY:
nfn = build_filename(filename2, ext);
@@ -399,8 +396,7 @@ static int ast_filehelper(const char *filename, const char *filename2, const cha
if (res)
ast_log(LOG_WARNING, "copy(%s,%s) failed: %s\n", fn, nfn, strerror(errno));
free(nfn);
- } else
- ast_log(LOG_WARNING, "Out of memory\n");
+ }
break;
case ACTION_OPEN:
if ((ret < 0) && ((chan->writeformat & f->format) ||