[asterisk-commits] seanbright: branch group/asterisk-cpp r168419 - /team/group/asterisk-cpp/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jan 10 20:12:14 CST 2009


Author: seanbright
Date: Sat Jan 10 20:12:13 2009
New Revision: 168419

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=168419
Log:
logger.c ftw

Modified:
    team/group/asterisk-cpp/main/logger.c

Modified: team/group/asterisk-cpp/main/logger.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/asterisk-cpp/main/logger.c?view=diff&rev=168419&r1=168418&r2=168419
==============================================================================
--- team/group/asterisk-cpp/main/logger.c (original)
+++ team/group/asterisk-cpp/main/logger.c Sat Jan 10 20:12:13 2009
@@ -64,7 +64,7 @@
 	LOG_DEBUG
 };
 
-#define SYSLOG_NLEVELS sizeof(syslog_level_map) / sizeof(int)
+#define SYSLOG_NLEVELS ((int) (sizeof(syslog_level_map) / sizeof(int)))
 
 #undef _ASTERISK_LOGGER_H	/* now include logger.h */
 #include "asterisk/logger.h"
@@ -155,7 +155,7 @@
 static FILE *qlog;
 
 /*! \brief Logging channels used in the Asterisk logging system */
-static char *levels[] = {
+static const char *levels[] = {
 	"DEBUG",
 	"EVENT",
 	"NOTICE",
@@ -215,12 +215,12 @@
 static struct logchannel *make_logchannel(const char *channel, const char *components, int lineno)
 {
 	struct logchannel *chan;
-	char *facility;
+	const char *facility;
 #ifndef SOLARIS
 	CODE *cptr;
 #endif
 
-	if (ast_strlen_zero(channel) || !(chan = ast_calloc(1, sizeof(*chan))))
+	if (ast_strlen_zero(channel) || !(chan = (struct logchannel *) ast_calloc(1, sizeof(*chan))))
 		return NULL;
 
 	if (!strcasecmp(channel, "console")) {
@@ -353,7 +353,7 @@
 			fprintf(stderr, "Unable to open logger.conf: %s; default settings will be used.\n", strerror(errno));
 		else
 			fprintf(stderr, "Errors detected in logger.conf: see above; default settings will be used.\n");
-		if (!(chan = ast_calloc(1, sizeof(*chan))))
+		if (!(chan = (struct logchannel *) ast_calloc(1, sizeof(*chan))))
 			return;
 		chan->type = LOGTYPE_CONSOLE;
 		chan->logmask = 28; /*warning,notice,error */
@@ -439,7 +439,7 @@
 	}
 	va_end(ap);
 
-	if (!(msg = ast_malloc(size + 1))) {
+	if (!(msg = (char *) ast_malloc(size + 1))) {
 		va_end(aq);
 		return;
 	}
@@ -447,7 +447,7 @@
 	vsnprintf(msg, size + 1, fmt, aq);
 	va_end(aq);
 
-	if (!(emsg = ast_malloc(size * 2 + 1))) {
+	if (!(emsg = (char *) ast_malloc(size * 2 + 1))) {
 		ast_free(msg);
 		return;
 	}
@@ -505,30 +505,30 @@
 
 static int rotate_file(const char *filename)
 {
-	char old[PATH_MAX];
-	char new[PATH_MAX];
-	int x, y, which, found, res = 0, fd;
-	char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
+	char oldfile[PATH_MAX];
+	char newfile[PATH_MAX];
+	int x, y, found, res = 0, fd;
+	const char *suffixes[4] = { "", ".gz", ".bz2", ".Z" };
 
 	switch (rotatestrategy) {
 	case SEQUENTIAL:
 		for (x = 0; ; x++) {
-			snprintf(new, sizeof(new), "%s.%d", filename, x);
-			fd = open(new, O_RDONLY);
+			snprintf(newfile, sizeof(newfile), "%s.%d", filename, x);
+			fd = open(newfile, O_RDONLY);
 			if (fd > -1)
 				close(fd);
 			else
 				break;
 		}
-		if (rename(filename, new)) {
-			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
+		if (rename(filename, newfile)) {
+			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, newfile);
 			res = -1;
 		}
 		break;
 	case TIMESTAMP:
-		snprintf(new, sizeof(new), "%s.%ld", filename, (long)time(NULL));
-		if (rename(filename, new)) {
-			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
+		snprintf(newfile, sizeof(newfile), "%s.%ld", filename, (long)time(NULL));
+		if (rename(filename, newfile)) {
+			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, newfile);
 			res = -1;
 		}
 		break;
@@ -536,9 +536,9 @@
 		/* Find the next empty slot, including a possible suffix */
 		for (x = 0; ; x++) {
 			found = 0;
-			for (which = 0; which < ARRAY_LEN(suffixes); which++) {
-				snprintf(new, sizeof(new), "%s.%d%s", filename, x, suffixes[which]);
-				fd = open(new, O_RDONLY);
+			for (size_t which = 0; which < ARRAY_LEN(suffixes); which++) {
+				snprintf(newfile, sizeof(newfile), "%s.%d%s", filename, x, suffixes[which]);
+				fd = open(newfile, O_RDONLY);
 				if (fd > -1) {
 					close(fd);
 					found = 1;
@@ -552,15 +552,15 @@
 
 		/* Found an empty slot */
 		for (y = x; y > 0; y--) {
-			for (which = 0; which < ARRAY_LEN(suffixes); which++) {
-				snprintf(old, sizeof(old), "%s.%d%s", filename, y - 1, suffixes[which]);
-				fd = open(old, O_RDONLY);
+			for (size_t which = 0; which < ARRAY_LEN(suffixes); which++) {
+				snprintf(oldfile, sizeof(oldfile), "%s.%d%s", filename, y - 1, suffixes[which]);
+				fd = open(oldfile, O_RDONLY);
 				if (fd > -1) {
 					/* Found the right suffix */
 					close(fd);
-					snprintf(new, sizeof(new), "%s.%d%s", filename, y, suffixes[which]);
-					if (rename(old, new)) {
-						fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
+					snprintf(newfile, sizeof(newfile), "%s.%d%s", filename, y, suffixes[which]);
+					if (rename(oldfile, newfile)) {
+						fprintf(stderr, "Unable to rename file '%s' to '%s'\n", oldfile, newfile);
 						res = -1;
 					}
 					break;
@@ -569,9 +569,9 @@
 		}
 
 		/* Finally, rename the current file */
-		snprintf(new, sizeof(new), "%s.0", filename);
-		if (rename(filename, new)) {
-			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, new);
+		snprintf(newfile, sizeof(newfile), "%s.0", filename);
+		if (rename(filename, newfile)) {
+			fprintf(stderr, "Unable to rename file '%s' to '%s'\n", filename, newfile);
 			res = -1;
 		}
 	}
@@ -1008,7 +1008,7 @@
 	int res = 0;
 
 	/* auto rotate if sig SIGXFSZ comes a-knockin */
-	(void) signal(SIGXFSZ, (void *) handle_SIGXFSZ);
+	(void) signal(SIGXFSZ, (sighandler_t) handle_SIGXFSZ);
 
 	/* start logger thread */
 	ast_cond_init(&logcond, NULL);
@@ -1141,7 +1141,7 @@
 		return;
 
 	/* Create a new logging message */
-	if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
+	if (!(logmsg = (struct logmsg *) ast_calloc(1, sizeof(*logmsg) + res + 1)))
 		return;
 
 	/* Copy string over */
@@ -1179,7 +1179,8 @@
 
 struct ast_bt *ast_bt_create(void) 
 {
-	struct ast_bt *bt = ast_calloc(1, sizeof(*bt));
+	struct ast_bt *bt = (struct ast_bt *) ast_calloc(1, sizeof(*bt));
+
 	if (!bt) {
 		ast_log(LOG_ERROR, "Unable to allocate memory for backtrace structure!\n");
 		return NULL;
@@ -1255,11 +1256,11 @@
 		now = ast_tvnow();
 		ast_localtime(&now, &tm, NULL);
 		ast_strftime(date, sizeof(date), dateformat, &tm);
-		datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
+		datefmt = (char *) alloca(strlen(date) + 3 + strlen(fmt) + 1);
 		sprintf(datefmt, "%c[%s] %s", 127, date, fmt);
 		fmt = datefmt;
 	} else {
-		char *tmp = alloca(strlen(fmt) + 2);
+		char *tmp = (char *) alloca(strlen(fmt) + 2);
 		sprintf(tmp, "%c%s", 127, fmt);
 		fmt = tmp;
 	}
@@ -1271,7 +1272,7 @@
 	if (res == AST_DYNSTR_BUILD_FAILED)
 		return;
 
-	if (!(logmsg = ast_calloc(1, sizeof(*logmsg) + res + 1)))
+	if (!(logmsg = (struct logmsg *) ast_calloc(1, sizeof(*logmsg) + res + 1)))
 		return;
 
 	strcpy(logmsg->str, ast_str_buffer(buf));
@@ -1316,7 +1317,7 @@
 {
 	struct verb *verb;
 
-	if (!(verb = ast_malloc(sizeof(*verb))))
+	if (!(verb = (struct verb *) ast_malloc(sizeof(*verb))))
 		return -1;
 
 	verb->verboser = v;




More information about the asterisk-commits mailing list