]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
null terminating snprintf
authorMichael Jerris <mike@jerris.com>
Mon, 22 Dec 2008 16:27:39 +0000 (16:27 +0000)
committerMichael Jerris <mike@jerris.com>
Mon, 22 Dec 2008 16:27:39 +0000 (16:27 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10907 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/esl/src/esl.c
libs/esl/src/esl_config.c
libs/esl/src/esl_event.c
libs/esl/src/include/esl.h

index 5616b2003a78d02aa1d1452ada430fa6947cc686..2c37f246f05c47697b54ce02cd262ac2c84d864f 100644 (file)
@@ -175,6 +175,24 @@ const char *esl_stristr(const char *instr, const char *str)
        return NULL;
 }
 
+#ifdef WIN32\r
+#ifndef vsnprintf\r
+#define vsnprintf _vsnprintf\r
+#endif\r
+#endif\r
+\r
+int esl_snprintf(char *buffer, size_t count, const char *fmt, ...)\r
+{\r
+       va_list ap;\r
+       int ret;\r
+\r
+       va_start(ap, fmt);\r
+       ret = vsnprintf(buffer, count-1, fmt, ap);\r
+       if (ret < 0)\r
+               buffer[count-1] = '\0';\r
+       va_end(ap);\r
+       return ret;\r
+}
 
 static void null_logger(const char *file, const char *func, int line, int level, const char *fmt, ...)
 {
index cdc8836d064677da381bfb92aeb5a95176ab6a47..9773559b08ba27956b2b24460c2727f404f16184 100644 (file)
@@ -43,7 +43,7 @@ int esl_config_open_file(esl_config_t *cfg, const char *file_path)
        if (file_path[0] == '/') {
                path = file_path;
        } else {
-               snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
+               esl_snprintf(path_buf, sizeof(path_buf), "%s%s%s", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR, file_path);
                path = path_buf;
        }
 
@@ -61,7 +61,7 @@ int esl_config_open_file(esl_config_t *cfg, const char *file_path)
                        int last = -1;
                        char *var, *val;
 
-                       snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
+                       esl_snprintf(path_buf, sizeof(path_buf), "%s%sopenesl.conf", ESL_CONFIG_DIR, ESL_PATH_SEPARATOR);
                        path = path_buf;
 
                        if ((f = fopen(path, "r")) == 0) {
index a901c52a616a6c8bcaf603b221fcd1277006e958..d60c87ed0a6ab3929404712965a239fb12c6e502 100644 (file)
@@ -481,7 +481,7 @@ esl_status_t esl_event_serialize(esl_event_t *event, char **str, esl_bool_t enco
                if (encode) {
                        esl_url_encode(hp->value, encode_buf, encode_len);
                } else {
-                       snprintf(encode_buf, encode_len, "[%s]", hp->value);
+                       esl_snprintf(encode_buf, encode_len, "[%s]", hp->value);
                }
 
                llen = strlen(hp->name) + strlen(encode_buf) + 8;
index 109382024740ce93b48ba67e6f770d073b17e203..806d6bc2f140d8b854bfaafafdb3d00dc0a07e48 100644 (file)
@@ -284,6 +284,8 @@ char *esl_url_decode(char *s);
 const char *esl_stristr(const char *instr, const char *str);
 int esl_toupper(int c);
 int esl_tolower(int c);
+int esl_snprintf(char *buffer, size_t count, const char *fmt, ...);\r
+
 
 typedef void (*esl_listen_callback_t)(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in addr);